javascript - Is throwing errors in constructors also prone to memory leaks? -
throwing exception in constructor can lead memory leaks: source 1, source 2. true oo languages c++, c#, java. wondering if javascript susceptible same memory-leak issue?
to illustrate, have js code:
widget = function(){ console.log("widget constructor"); }; foo = function(){ console.log("foo constructor"); this.w = new widget(); throw new error(); }; foo.prototype.dispose = function() { delete this.w; }; var f = new foo; f.dispose();
obviously i'll dispose()
never called, in case curious fate of f.w
object? remain in memory , cannot cleared in way (causing memory leaks)? or perhaps garbage collector smart enough , recognizes not referenced anywhere , disposes it? how handled different js engines? if true how avoid it?
Comments
Post a Comment