Skip to content

Commit

Permalink
Fix memory hike caused by repeatedly switching inspectors (#17605)
Browse files Browse the repository at this point in the history
* Fix memory hike caused by repeatedly switching inspectors

* refine code

---------

Co-authored-by: cocos <[email protected]>
  • Loading branch information
knoxHuang and cocos authored Sep 5, 2024
1 parent ef76162 commit b990d85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions editor/inspector/contributions/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ const Elements = {

Editor.Message.addBroadcastListener('asset-db:asset-change', panel.__assetChanged__);

Elements.panel.i18nChangeBind = Elements.panel.i18nChange.bind(panel);
Editor.Message.addBroadcastListener('i18n:change', Elements.panel.i18nChangeBind);
panel.i18nChangeBind = Elements.panel.i18nChange.bind(panel);
Editor.Message.addBroadcastListener('i18n:change', panel.i18nChangeBind);

panel.history = new History();
},
Expand Down Expand Up @@ -164,6 +164,7 @@ const Elements = {
panel.__assetChangedHandle__ = undefined;
}

Editor.Message.removeBroadcastListener('i18n:change', panel.i18nChangeBind);
Editor.Message.removeBroadcastListener('asset-db:asset-change', panel.__assetChanged__);

delete panel.history;
Expand Down
8 changes: 5 additions & 3 deletions editor/inspector/contributions/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1160,8 +1160,8 @@ const Elements = {
event.stopPropagation();
});

Elements.node.i18nChangeBind = Elements.node.i18nChange.bind(panel);
Editor.Message.addBroadcastListener('i18n:change', Elements.node.i18nChangeBind);
panel.i18nChangeBind = Elements.node.i18nChange.bind(panel);
Editor.Message.addBroadcastListener('i18n:change', panel.i18nChangeBind);
},
async update() {
const panel = this;
Expand Down Expand Up @@ -1404,7 +1404,9 @@ const Elements = {
}
},
close() {
Editor.Message.removeBroadcastListener('i18n:change', Elements.node.i18nChangeBind);
const panel = this;

Editor.Message.removeBroadcastListener('i18n:change', panel.i18nChangeBind);
},
i18nChange() {
const panel = this;
Expand Down

0 comments on commit b990d85

Please sign in to comment.