parro-it/electron-localshortcut

memory leakage after calling unregisterAll

gehuangyi20 opened this issue · 3 comments

In the first time of calling register(), the following code line 167-177 register the event for the window

if (win !== ANY_WINDOW) {
    win.on('close', _unregister('the window was closed.'));

    win.on('hide', _unregister('the window was hidden.'));

    win.on('minimize', _unregister('the window was minimized.'));

    win.on('restore', _register('the window was restored from minimized state.'));

    win.on('show', _register('the window was showed.'));
}

However, these registered event are not freed after calling unregisterAll. This will cause memory leakage.

Good catch @gehuangyi20, thank you! Would you mind doing a PR to correct this?

@parro-it Sure. I can do that. It may take some time. Actually, these event callback functions are anonymous functions. These functions need to be cached somewhere so that they can be unregistered later. Would you mind me to add some extra data structure like object and map to fix this?

Awesome @gehuangyi20!

Would you mind me to add some extra data structure like object and map to fix this?

No, feel free 👍