我刚刚发现,当使用 remove() 函数时,匹配的元素并没有从 jQuery 对象中移除,只是从 DOM 中移除。
Removes all matched elements from the DOM. This does NOT remove them from the jQuery object, allowing you to use the matched elements further.
如果一个 web 应用程序不断地从 dom 中添加和删除元素,这肯定会消耗越来越多的内存吗?有人可以确认是否是这种情况吗?可以做些什么来避免这种情况?
最佳答案
我认为一旦超出范围,它就会(最终)被垃圾回收。如果您遇到内存使用过多的问题,尽管您可以尝试对返回的对象使用 delete 运算符。
关于javascript - $ ('#foo' ).remove() 可能存在 jQuery 内存问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1052857/