Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • 1
    The workaround removed the click handler, and you lose functionality. The solution is to remove it on unload. You don't need to remove both references, just one of them. That is, you don't need to remove the element from the DOM Commented Sep 22, 2011 at 18:10
  • 1
    The IBM site (before they took it down) mentioned that a workaround would be to set obj=null after setting everything. Commented Sep 22, 2011 at 18:13
  • The work-around removed the click handler only when I was removing the object from the DOM and intending for the object to be destroyed. If you want the object to stay around, then the memory associated with it should stay around - that is not a leak. Commented Sep 22, 2011 at 18:14
  • @Adam - setting obj to null in your example above doesn't accomplish much with relation to bigString. You still have bigString as an attribute on your object and all that memory is still being used. It would remove the circular reference between JS<==>DOM so if you later removed obj from the DOM, then it would get freed appropriately. That could protect against that. But, the issue that I wanted to make clear is this is only a leak if you later remove the object from the DOM and expect it to be freed. Commented Sep 22, 2011 at 18:16
  • @jfriend00: The code wants a click handler do to something. You are simply adding a handler and removing it immediately, that doesn't make sense. Like I mentioned before, the way to address the issue is to remove obj.onclick when the page is unloaded, so that you still get your alert when clicking the element, but the leak doesn't persist when you reload the page Commented Sep 22, 2011 at 18:18