For an Ajax application, I'm repeatedly using jQuery's html()
method to update a DOM container (overwriting HTML content, then binding elements to event listeners).
Are the event listeners that were attached to the destroyed content correctly removed by jQuery, or is there a risk of memory leaks? (There are already a few related questions out here, but I couldn't find the answer).
Yes, all events and data are cleaned up when you remove or replace content with jQuery methods. It is done using the internal cleanData
method.
https://github.com/jquery/jquery/blob/1.9-stable/src/manipulation.js#L242 https://github.com/jquery/jquery/blob/1.9-stable/src/manipulation.js#L746
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With