バックボーンのメモリ リークを解決する際に問題が発生しています。これまでのところ、ビューが DOM から削除されているときに jquery CleanData を使用してビューをクリーンアップしようとしました。
ビューが削除されるたびに (jQuery .html() を介しても)、ビューの収集を停止するすべての参照を理論的に削除する dispose() メソッドにヒットします。残念ながら、アプリはメモリを構築するだけです
以下のコード、
Backbone.View.prototype.dispose = function(){
// unbind all events, so we don't have references to child views
this.unbind();
this.off();
// if we have a collection - unbind all events bound to this context
this.collection && this.collection.off(null, null, this);
// do the same with a model
this.model && this.model.off(null, null, this);
delete this;
};
きれいなデータ:
$.cleanData = function( elems ) {
$.each( elems, function( i, elem ) {
if ( elem ) {
$(elem).trigger("dispose");
}
});
oldClean(elems);
};
コードは機能し、dispose がヒットします (ビューにイベントを追加しました) が、ページを変更しても収集されません。
(dispose イベントについて..) すべてのビューで remove を明示的に呼び出すわけではありません。アプリ コンテナが空になると、jQuery は cleanData を実行します。イベント破棄を追加し、クリーンデータでその関数をトリガーします