javascript - Memory leaks and jQuery plugin -


i'm writing destroy method jquery plugin. i'm concerned potential memory leaks caused references dom objects persisting after destroy method has been called. code below have potential cause memory leak?

jquery.fn.foo = function(){     var $bar = $('.bar');      $bar.on('click.foo', function(){         var $baz = $('.baz');     });      this.destroyfoo = function(){         $bar.off('click.foo');         //is necessary avoid orphan node?         $bar = null;     };      return this; };  var $qux = $('.qux').foo();  $qux.destroyfoo(); 

looks fine me. variable $bar declared within function scope won't accessible outside of it.

$bar = null; - enough clear reference element.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -