且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何销毁JavaScript对象?

更新时间:2022-06-12 20:58:18

您可以将所有代码放在一个名称空间中,如下所示:

You could put all of your code under one namespace like this:

var namespace = {};

namespace.someClassObj = {};

delete namespace.someClassObj;

使用 delete 关键字将删除参考对于该属性,但在低级别,JavaScript垃圾收集器(GC)将获得有关要回收哪些对象的更多信息。

Using the delete keyword will delete the reference to the property, but on the low level the JavaScript garbage collector (GC) will get more information about which objects to be reclaimed.

您还可以使用Chrome开发者工具获取应用的内存配置文件,以及应用中的哪些对象需要按比例缩小。

You could also use Chrome Developer Tools to get a memory profile of your app, and which objects in your app are needing to be scaled down.