0

我是 javascript/html 应用程序开发的新手。单击时,我有一个带有按钮的 page1 将我带到 page2。每次我从第 1 页转到第 2 页然后导航回第 1 页时,内存使用量就会增加 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();
        }

    });
})();

这种模式有什么明显的问题吗?

4

0 回答 0