区分Chrome堆快照中非泄漏的泄漏

时间:2019-02-01 15:17:48

标签: javascript memory-leaks google-chrome-devtools

在Chrome开发人员工具或类似工具中检查堆快照时,如何区分“必须”保留在内存中的对象与泄漏?

之所以问这个问题,是因为我注意到执行以下代码时,唯一的事实是一个类扩展了另一个类(因此不使用它们),这会在堆中创建一个对象。

// script.ts
class A {}
class B extends A {}

// script.js
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var A = /** @class */ (function () {
    function A() {
    }
    return A;
}());
var B = /** @class */ (function (_super) {
    __extends(B, _super);
    function B() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return B;
}(A));

screenshot

在这种简单情况下,只有一个类(B)扩展了另一个类(A),但是我尝试了多个类(C扩展了A,D扩展了A),并且在堆查看器中我看到了许多A我多次扩展A实例,所以当寻找泄漏时,这些事情对我来说很混乱。

所以我的“真实”问题是:在真实应用程序中(本例中为Angular),我如何区分纯粹与对象泄漏相关的对象(在本例中为继承)?

0 个答案:

没有答案