Freeing memory used by unattached DOM nodes in Javascript - Stack Overflow

As part of my application, I'm putting together a set of small Dom nodes that are not shown all at

As part of my application, I'm putting together a set of small Dom nodes that are not shown all at once. I'm storing them in an internal array. The user can invoke their display in which case I reparent them to the div that is used to display them. That's all well and good. But when it's time to replace all of them with new ones, I want to destroy the old ones (effectively deallocate them). Otherwise, over time, memory usage could grow exponentially. How do I force the browser js engine to do this? Is just setting each of the items in my array of Dom nodes to null enough? Is there something else I have to do? Or maybe I don't have to worry about this at all?

As part of my application, I'm putting together a set of small Dom nodes that are not shown all at once. I'm storing them in an internal array. The user can invoke their display in which case I reparent them to the div that is used to display them. That's all well and good. But when it's time to replace all of them with new ones, I want to destroy the old ones (effectively deallocate them). Otherwise, over time, memory usage could grow exponentially. How do I force the browser js engine to do this? Is just setting each of the items in my array of Dom nodes to null enough? Is there something else I have to do? Or maybe I don't have to worry about this at all?

Share Improve this question asked Feb 8, 2009 at 18:24 KarimKarim 18.6k14 gold badges63 silver badges72 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

If you set each item to null, they will be automatically garbage collected.

Yes, setting the items to null should be ok… Except that some implementation details must be taken care of with Internet Explorer: its handling of circular references is dodgy. See http://msdn.microsoft./en-us/library/bb250448.aspx

Circular References—When mutual references are counted between Internet Explorer's COM infrastructure and any scripting engine, objects can leak memory

So you have to break circular references in some cases.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745586819a4634591.html

相关推荐

  • Freeing memory used by unattached DOM nodes in Javascript - Stack Overflow

    As part of my application, I'm putting together a set of small Dom nodes that are not shown all at

    10小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信