will destroying a jQuery dialog remove any handlers attached to elements inside it?
I've noticed some memory leaks in an app i'm building, after playing around with for a while FF will start to use up more an开发者_运维百科d more memory (upwards to 1 000 000 k).
I've done some research and found that if i do a $(selector).html(some stuff)
to replace the contents of something the jQuery handlers from the elements previous content will not be removed and cause some problems, i've fixed all those.
the question i have is if i destroy a dialog with $(mydialog).dialog('destroy');
will the handlers that were attached to various elements that were in that dialog be removed?
Thanks!
No, they will not be removed, the dialog element itself will be returned to it's previous state, the elements inside aren't touched.
The dialog widget itself, the buttons, title bar, close button, etc. are cleaned up, but the element you turned into a dialog is not affected and not cleaned up. You need to either .empty()
or .remove()
the whole element for that.
I'm not sure if destroying a dialog with the provided method removes any contained event handlers, but you can always do:
$(selector).empty();
instead of:
$(selector).html('blahblah'); // or .html('');
and that will get rid of any event handlers bound to any replaced elements, and thus avoid memory leaks.
精彩评论