-
Notifications
You must be signed in to change notification settings - Fork 20.6k
.off() does not clean up empty cache entries #1760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Comment author: psquared Perhaps this is a better suggestion than the one I made above--adding something like this to the end of Data.remove() seems to help: if (jQuery.isEmptyObject(cache)) { this.discard(owner); } |
Comment author: dmethvin @rwaldron could you take a look? |
Comment author: gibson042 In general, we do not support mixing native DOM manipulation with jQuery. This is close to $( el ).data({ leaks: true })[0].parentNode.removeChild( el ), but distinct enough that it may be worth looking into a small fix. |
Comment author: dmethvin I agree with that, there are plenty of ways you can get into trouble if you use native methods to remove elements behind jQuery's back. But in the 1.x branch if you remove all events and there is no other data in the object, it removes the data object preemptively. e.g., |
Comment author: dmethvin I'll mark this valid pending investigation. Since events are often the only thing in the data cache it would be helpful to remove them when all events are gone. |
Once the changes to |
Now that the data changes have landed, what needs to be done here? |
If you attach a couple of handlers to elements & then .off() them without removing elements then you still have a leak. This is way less serious now as removing elements makes the data go away but I'd say part of the issue is still applicable. |
It looks like we take care of the no-more-events case now? Line 220 in 62d5579
|
PR submitted. |
Originally reported by psquared at: http://bugs.jquery.com/ticket/14674
Even if all event handlers are removed with .off(), an empty cache entry is left in data_priv. Unfortunately, those empty cache entries remain if elements are removed using some method other than .remove(), causing a memory leak.
Test Environment:
Chrome 31.0.1650.63, jQuery 2.0.3
Steps to Reproduce:
Expected Results:
No memory leaks.
Actual Results:
An orphaned cache entry remains in data_priv.
Example:
http://jsfiddle.net/Rx3v3/
Additional info:
Modifying the last block of jQuery.event.remove() as below seems to alleviate the problem.
Issue reported for jQuery 2.0.3
The text was updated successfully, but these errors were encountered: