Does Javascript remove event handlers of deleted DOM elements?

If I attached a bunch of events to some DOM elements - and then remove them - will the memory used for their event handlers or other attributes still be used?

I ask because I want to know if I will use a bunch of memory if I keep refilling an area of a page with new elements from AJAX requests and binding events to them - only to delete them and repeat the process when a new AJAX result comes in.


Yes, modern browsers (eventually) release the memory used by event handlers in DOM nodes. However, old versions of Internet Explorer don't, so it's always good practice to remove event listeners before removing the nodes from the DOM.

This is a good article for understanding what's going on:

Need Your Help

Why has db:create stopped working?

ruby-on-rails postgresql migration

Until recently db:create worked just fine, but now it is failing with the stacktrace I've posted below. It's a String can't be coerced into Fixnum error.

What will $( “li”, “li.item-ii” ) do?

jquery jquery-selectors

This might be a noob question buy Will $( "li", "li.item-ii" ) select all li's and the li.item-ii inside the '' or select only li's which are descendants of li.item-ii ?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.