javascript - Will adding the parent object of a child object to the listeners lead to a retain cycle in Node.js? -


i'm not familiar retain cycles in node.js coming more objective-c/ios, wrote bit of code i'm hoping not lead retain cycle. i'm not sure how intelligently v8 deals garbage collection or how intelligent i'm supposed @ this!

in example, create object supposed handle making data connection , feeding data parent object. in order this, use eventemitter .on functions register parent object functions. parent object gets released when of data processed, after create retain cycle between parent , child objects? sample code

// create sonardata necessary information this.sonardata = new sonardata( this.key, this.size )  // hook events .on( 'error', this.handleerror.bind( ) ) .on( 'done', this.handledone.bind( ) ) .on( 'data', this.handledata.bind( ) ); 

when parent object released, if there no other references child object , no active message handlers on child object, child object garbage collected fine. javascript garbage collectors don't have issues retain cycles. work whether code still reachable other active code or not.

so, 2 objects each refer each other, neither of reachable other code garbage collected.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -