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