释放Javascript中未连接的DOM节点使用的内存 [英] Freeing memory used by unattached DOM nodes in Javascript

查看:118
本文介绍了释放Javascript中未连接的DOM节点使用的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为我的应用程序的一部分,我正在组合一组未同时显示的小型Dom节点。我将它们存储在内部数组中。用户可以调用他们的显示,在这种情况下,我将它们重新显示到用于显示它们的div。这一切都很好。但是,当用新的替换所有这些时,我想要破坏旧的(有效地解除它们)。否则,随着时间的推移,内存使用量可能呈指数级增长。如何强制浏览器js引擎执行此操作?只是将我的Dom节点数组中的每个项设置为null?我还有别的办法吗?或者我可能根本不用担心这个问题?

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?

推荐答案

如果你将每个项目设置为null,它们将是自动垃圾收集。

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

这篇关于释放Javascript中未连接的DOM节点使用的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆