jQuery.ui.widget memory leak
by Yoshiharu Kamata
HTML
<script src="https://raw.github.com/jquery/jquery-ui/master/ui/jquery.ui.core.js"></script>
<script src="https://raw.github.com/jquery/jquery-ui/master/ui/jquery.ui.widget.js"></script>
<div id="container">loading...</div>
<div id="console"></div>
JavaScript
(function($,undefined){
$.Widget.prototype._bind =function( element, handlers ) {
// no element argument, shuffle and use this.element
if ( !handlers ) {
handlers = element;
element = this.element;
} else {
// accept selectors, DOM elements
element = $( element );
this.bindings = this.bindings.add( element );
}
var instance = this;
$.each( handlers, function( event, handler ) {
function handlerProxy() {
// allow widgets to customize the disabled handling
// - disabled as an array instead of boolean
// - disabled class as method for disabling individual parts
if ( instance.options.disabled === true ||
$( this ).hasClass( "ui-state-disabled" ) ) {
return;
}
return ( typeof handler === "string" ? instance[ handler ] : handler )
.apply( instance, arguments );
/*if( typeof handler === "string" ){
return(instance[ handler ]());
}else{
return(handler.apply( instance, arguments ));
}*/
}
var match = event.match( /^(\w+)\s*(.*)$/ ),
eventName = match[1] + "." + instance.widgetName,
selector = match[2];
if ( selector ) {
instance.widget().delegate( selector, eventName, handlerProxy );
} else {
element.bind( eventName, handlerProxy );
}
});
};
})(jQuery);
// test code
(function($,undefined){
var count = 0;
$.widget("ui.dummy",{
_destroy: function(){
$("#console").text("call destroy:"+count++);
// $.Widget.prototype.destroy.call( this );
}
});
})(jQuery);
setInterval(function(){
$("#container")
.empty()
.append("<div...