How to avoid EventEmitter Max Listeners warning? #364

Closed
opened 2026-01-29 16:37:42 +00:00 by claunia · 3 comments
Owner

Originally created by @win32nipuh on GitHub (Jul 17, 2019).

Originally assigned to: @GregorBiswanger on GitHub.

I use Ipc to exchange data:

     <button id="cmdShowData">Process</button>

    <script>
        (function () {
            const { ipcRenderer } = require("electron");

            document.getElementById("cmdShowData").addEventListener("click", () => {
                ipcRenderer.send("doProcess", 'args');
            });

            ipcRenderer.on('sendData1', (event, msg) => {
                document.getElementById("ResponseOK").innerHTML = msg;
            });
        }());
    </script>

But after 11 page loadings I receive:

(node:29284) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 doProcess listeners added. Use emitter.setMaxListeners() to increase limit

How and where I can increase this limit?
Is it problem or it is warning only?

Originally created by @win32nipuh on GitHub (Jul 17, 2019). Originally assigned to: @GregorBiswanger on GitHub. I use Ipc to exchange data: ``` <button id="cmdShowData">Process</button> <script> (function () { const { ipcRenderer } = require("electron"); document.getElementById("cmdShowData").addEventListener("click", () => { ipcRenderer.send("doProcess", 'args'); }); ipcRenderer.on('sendData1', (event, msg) => { document.getElementById("ResponseOK").innerHTML = msg; }); }()); </script> ``` But after 11 page loadings I receive: > (node:29284) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 doProcess listeners added. Use emitter.setMaxListeners() to increase limit How and where I can increase this limit? Is it problem or it is warning only?
claunia added the question label 2026-01-29 16:37:42 +00:00
Author
Owner

@GregorBiswanger commented on GitHub (Jul 26, 2019):

The code is called again and again when you reload your page. You should therefore not repeat an event registration.

It is best to register your code globally rather than directly on the same page. Or use the unload event and cancel the registrations.

https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event

@GregorBiswanger commented on GitHub (Jul 26, 2019): The code is called again and again when you reload your page. You should therefore not repeat an event registration. It is best to register your code globally rather than directly on the same page. Or use the unload event and cancel the registrations. https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event
Author
Owner

@ZedZipDev commented on GitHub (Jul 28, 2019):

Thanx, ok.
Now I do it in Controller/Action method.
But when I click menu the Controller object created again, its constructor etc.
Where is the best place to register it?

@ZedZipDev commented on GitHub (Jul 28, 2019): Thanx, ok. Now I do it in Controller/Action method. But when I click menu the Controller object created again, its constructor etc. Where is the best place to register it?
Author
Owner

@GregorBiswanger commented on GitHub (May 10, 2020):

It's best to use a single-page app, or see the code from our demo app.
Alternatively, you can also use Blazor.

https://github.com/ElectronNET/electron.net-api-demos

@GregorBiswanger commented on GitHub (May 10, 2020): It's best to use a single-page app, or see the code from our demo app. Alternatively, you can also use Blazor. https://github.com/ElectronNET/electron.net-api-demos
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#364