我的javascript应用程序内存泄漏

时间:2013-05-15 04:36:42

标签: javascript memory knockout.js memory-leaks

我是javascript / html app开发的新手。我点击了带有按钮的page1将我带到page2。每次我转到page1到page2然后导航回page1时,内存使用量会增加10 MB,并且随着我的使用而不断增加。这是page1的模式。

以下是Page1viewModel.js

的代码
var __extends = this.__extends || function (d, b) {
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};

var Page1ViewModel = (function (_super) {
    "use strict";

    __extends(ViewModel, _super);
    >>>>
    some variables declared here
    >>>>

    function ViewModel(modelParameter) {
        _super.call(this, modelParameter);
        var self = this;
    >>>>
    some code here
    >>>>
        this.unloaded(false);
    };

    // Observable to tell the view when the page has been unloaded.
    ViewModel.prototype.unloaded = ko.observable(false);

    // Method that is called on the app exiting this page.
    ViewModel.prototype.unload = function () {
    <<<code to remove handlers>>>>
        this.unloaded(true);
    };

   <<< some more prototype functions>>>

    return ViewModel;
})(BaseViewModel);

这是Page1.js的代码

(function () {
    "use strict";
    var viewModel,
        view;
    WinJS.UI.Pages.define("/pages/Page1.html", {
        ready: function (element, options) {

            viewModel = new Page1ViewModel(window.appModel);
            view = new Page1View(element, viewModel);

            ko.applyBindings(view, element.children[0]);

            view.initialize();
        },
        unload: function (element) {
            view.unload();
            viewModel.unload();
        }

    });
})();

这种模式有什么明显的错误吗?

0 个答案:

没有答案