danielnieto / electron-download-manager

Manage downloadItems from Electron's BrowserWindows without user interaction, allowing single file download and bulk downloading
MIT License
119 stars 51 forks source link

Prevent memory leaks from .on() when register called multiple times #50

Open azmodii opened 3 years ago

azmodii commented 3 years ago

In my current application, the user can select a download location. This can be updated many times in a single session. Due to being unable to update the path once a handler is registered, I have resorted to calling DownloadManager.register to update the path. The existing code causes multiple handlers to be registered when calling DownloadManager.register multiple times.

This causes the following output from node:

(node:3256) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 browser-window-created listeners added to [App]. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:390:17)
    at App.addListener (events.js:406:10)
    ...

A more permanent solution would be an API to allow the update of the options parameter, but the module still should not cause this behaviour if used incorrectly. This PR fixes that behaviour.