-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend listener removal in BusHelper #37
Conversation
- Adds a clean-up function `removeListeners` that in addition to the already existing PropertiesChanged removal on itself (in `Device.disconnect`) also removes PropertiesChanged event listeners on the _propsProxy object. - Adds use of this clean-up function in `Device.disconnect`.
Bump :) Any feedback? |
This approach looks better, but I have to try it. I will next weekend, promised. |
Related issue, after calling Adapter.devices in a loop once every 5 seconds I start to get This is the code in question, called from a const devices = await adapter.devices();
for (let i = 0; i < devices.length; i++) {
try {
const device = await adapter.getDevice(devices[i]);
const name = await device.getName();
const rssi = await device.getRSSI();
await device.disconnect();
... I've tried the changes in this PR but they didn't affect the error. |
I ended up using this change combined with dbusjs/node-dbus-next#110 Since none got merged still using the forked versions explicitly binding the github urls in Example, temporary forked node-ble which has this change and a reference to forked dbus-next change:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirm that exists a memory leak, but the provided fix may introduce a different bug.
removeListeners () { | ||
this.removeAllListeners('PropertiesChanged') | ||
if (this._propsProxy !== null) { | ||
this._propsProxy.removeAllListeners('PropertiesChanged') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tuxedoxt I understand that you want to delete this listener because it generate a memory leak, but I think that if you do this in this way, you creates a different bug.
What if the user connects again this device? No code line will subscribe again on 'PropertiesChanged' events, so the library will not work correctly.
I think that this bug requires a different fix.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. I see what you mean.
As I see it, additionally setting
this._ready = false
should make _prepare
reattach listener. However also does other things, like assigns completely new _propsProxy
and _ifaceProxy
objects. Would more clean-up be needed there or is this feasible?
Any chance this will get merged soon? |
Another bump :) |
Released with v1.10 |
* Extend listener removal in BusHelper - Adds a clean-up function `removeListeners` that in addition to the already existing PropertiesChanged removal on itself (in `Device.disconnect`) also removes PropertiesChanged event listeners on the _propsProxy object. - Adds use of this clean-up function in `Device.disconnect`. * Fix re-use after listener removal in BusHelper * Add test cases for BusHelper.removeListeners
Hello,
if the intended use of
Device.disconnect
also is to clean up the remaining event listeners this PR extends this to include the leftoverBusHelper._propsProxy
event listeners adding a new functionBusHelper.removeListeners
for this purpose.This seems to do it for my current issue in #35.