...$ ('# target'). html ('') will delete th...">

How to check if a memory leak occurs when an item is removed from the DOM?

<div id="target"> ... </div> 

$ ('# target'). html ('') will delete the content, but how to check if listeners or anything else that stores memory is deleted at the same time?

+2
javascript jquery memory-leaks
source share
3 answers

Standard JavaScript does not define tools for garbage collection of the interpreter, so I do not think that this is possible.

However, since deleting nodes is not an unusual operation, I would not worry about browser memory leaks in this case. Indeed, as Piskvor said, the memory will probably not be released immediately, but when the garbage collector will eventually start.

+2
source share

I'm not sure how you can spot a leak in JavaScript (using JavaScript). but there are JavaScript leak detection tools

+2
source share

I am not an expert on this, but since you are using jQuery you should use $('#target').empty() . This separates all event handlers before deleting children. When they are assembled before the browser, but this ensures that they will be collected when the time comes. You can also use $.remove() to get rid of the selected item and all child elements.

http://api.jquery.com/empty

0
source share

All Articles