页面刷新时Javascript内存泄漏;补救? [英] Javascript memory leak on page refresh; remedy?

查看:129
本文介绍了页面刷新时Javascript内存泄漏;补救?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IE页面刷新时遇到内存泄漏(正如我在中所述 SO post)。

I am experiencing a memory leak in IE that occurs upon a page refresh (as I described in this SO post).

此时我想知道的是:有没有办法,在文档卸载事件上(可以在页面刷新或关闭时调用,以清除所有内容?我正在寻找一个简单的解决方案,以确保一切都被破坏,以避免泄漏。这是否可能,或者我是否必须继续查看泄漏的详细信息并逐个对象地进行修复?

All I want to know at this point is: is there a way, on the document "unload" event (which could get called when the page refreshes or closes), to clear EVERYTHING? I'm looking for a simple solution that would ensure that everything gets destroyed in order to avoid the leak. Is this even possible, or do I have to continue looking into the details of the leak and fixing it on an object by object basis?

更新:好吧,也许我的描述性不够。我不能(至少我认为我不能)只将我的所有对象设置为null:我有点击事件的事件处理程序等所以应用程序需要不断生效直到它关闭。此外,如果我考虑在卸载方法(在退出页面时调用)中将所有内容归零,那么我的所有对象都必须具有全局范围(右)?解决这个问题的最佳方法是什么?有没有办法获取所有引用对象的列表,所以我可以将它们为空?我应该将我使用的每个对象添加到一个数组中,以便以后可以取消引用吗?

Update: Ok maybe I wasn't descriptive enough. I can't (at least I dont think I can) just set all of my objects to null: I have event handlers for click events etc. so the application needs to be "live" constantly until it is closed. Also if I then think about just nulling everything out in an "unload" method (called when the page is exited), then all my objects would have to have global scope (right)? What is the best way to remedy this? Is there a way to get a list of all referenced objects so I can null them? Should I add every object I use to an array so that I can dereference it later?

推荐答案

将对象设置为null并将它们设置为空不会泄露。

Set your objects to null and they won't be leaked.

这篇关于页面刷新时Javascript内存泄漏;补救?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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