-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Memory leak - polyfill #215
Comments
Functions passed as arguments to NodeDataChannel.PeerConnection cannot be released by the GC onStateChange |
Hello and thank you for reporting. |
This snippet probably fixes the leak, at least I don't notice any leaks anymore with this one import NodeDataChannel from 'node-datachannel';
function dummy() {}
class _PeerConnection extends NodeDataChannel.PeerConnection {
hooked = {
onStateChange: null,
onIceStateChange: null,
onSignalingStateChange: null,
onGatheringStateChange: null,
onDataChannel: null,
onLocalDescription: null,
onLocalCandidate: null
};
constructor(a, b) {
super(a, b);
}
onStateChange(l) {
this.hooked.onStateChange = l;
super.onStateChange((param) => this.hooked.onStateChange(param));
}
onIceStateChange(l) {
this.hooked.onIceStateChange = l;
super.onIceStateChange((param) => this.hooked.onIceStateChange(param));
}
onSignalingStateChange(l) {
this.hooked.onSignalingStateChange = l;
super.onSignalingStateChange((param) => this.hooked.onSignalingStateChange(param));
}
onGatheringStateChange(l) {
this.hooked.onGatheringStateChange = l;
super.onGatheringStateChange((param) => this.hooked.onGatheringStateChange(param));
}
onDataChannel(l) {
this.hooked.onDataChannel = l;
super.onDataChannel((param) => this.hooked.onDataChannel(param));
}
onLocalDescription(l) {
this.hooked.onLocalDescription = l;
super.onLocalDescription((param1, param2) => this.hooked.onLocalDescription(param1, param2));
}
onLocalCandidate(l) {
this.hooked.onLocalCandidate = l;
super.onLocalCandidate((param1, param2) => this.hooked.onLocalCandidate(param1, param2));
}
removeEvents() {
for (let key in this.hooked) {
this.hooked[key] = function () {};
}
setTimeout(() => (this.hooked = null), 30);
super.onStateChange(dummy);
super.onIceStateChange(dummy);
super.onSignalingStateChange(dummy);
super.onGatheringStateChange(dummy);
super.onDataChannel(dummy);
super.onLocalDescription(dummy);
super.onLocalCandidate(dummy);
this.hooked = null;
}
close() {
this.removeEvents();
super.close();
}
}
NodeDataChannel.PeerConnection = _PeerConnection; |
Hello, In your snippet, you are resetting all functions and then closing the connection.
|
I think I've come across a similar problem when trying to remove this forced exit from a test suite. Something is keeping the Node.js process from exiting - running with why-is-node-running reveals:
Line 67 of the
Is there some extra teardown that's needed when the peer connection is closed? |
@achingbrain It appears the ICE state change callback is not reset on destruction in the wrapper. I'll push a fix. |
@murat-dogan It should be fixed by #221 |
Good catch! I merged it. |
I found a memory leak in the polyfill, the context data is stored in memory. I started removing #peerConnection from _RTCPeerConnection (like _RTCPeerConnection._peerConnection = null ), the situation becomes to normal. I'm not good at fixing leaks properly. I hope this information will help the developer fix the memory leak
The text was updated successfully, but these errors were encountered: