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

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

问题描述

我在 IE 中遇到了页面刷新时发生的内存泄漏(正如我在 this 所以帖子).

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天全站免登陆