如果您想对 Javascript 中的变量强制进行垃圾回收,将其设置为 null 还是 undefined 更好? [英] If you want force garbage collection on a variable in Javascript, is it better to set it as null or undefined?

查看:69
本文介绍了如果您想对 Javascript 中的变量强制进行垃圾回收,将其设置为 null 还是 undefined 更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JS 框架开发 Android 游戏.我想确保一些对象在我使用完毕后被垃圾回收.我如何强制它?我应该使用 null 还是 undefined?

I am developing an Android game using JS framework. I want to make sure that some of the objects are garbage collected once I am done using them. How do i force it? Should I use null or undefined?

推荐答案

最好的建议是在使它们有资格进行垃圾回收的范围内定义它们.这意味着不要使用永远不符合收集条件的全局变量.而是将他们声明为本地人.

Best advice is to define them in scope that makes them eligible for garbage collection. This means don't use global variables that never become eligible for collection. Instead declare them as locals.

这篇关于如果您想对 Javascript 中的变量强制进行垃圾回收,将其设置为 null 还是 undefined 更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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