Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible jQuery memory issues with $('#foo').remove()?

I've just discovered that when the remove() function is used, the matched elements are not removed from the jQuery object, just the DOM.

According to the remove() documentation:

Removes all matched elements from the DOM. This does NOT remove them from the jQuery object, allowing you to use the matched elements further.

Surely if a web app keeps on adding and removing elements from the dom, this will keep using up more and more memory? Can someone confirm if this is the case? What can be done to avoid this?

like image 494
andyuk Avatar asked Jun 27 '09 13:06

andyuk


1 Answers

I think that it would be garbage collected (eventually) once it falls out of scope. If you're having problems with excessive memory use, though you might try using the delete operator on the returned object.

like image 165
tvanfosson Avatar answered Sep 23 '22 22:09

tvanfosson