Does jQuery remove event listeners from destroyed DOM content?

javascript, jquery, jquery-events, memory-leaks

Solution

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

Problem

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).

Original source