Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vrender-animate",
"comment": "fix: fix memory leak by properly removing listener",
"type": "none"
}
],
"packageName": "@visactor/vrender-animate"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vrender-components",
"comment": "fix: fix memory leak by properly removing listener",
"type": "none"
}
],
"packageName": "@visactor/vrender-components"
}
10 changes: 7 additions & 3 deletions packages/vrender-animate/src/ticker/default-ticker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ export class DefaultTicker extends EventEmitter implements ITicker {
init(): void {
this.interval = 16;
this.status = STATUS.INITIAL;
application.global.hooks.onSetEnv.tap('graph-ticker', () => {
this.initHandler(false);
});
application.global.hooks.onSetEnv.tap('graph-ticker', this._handleGraphTick);
if (application.global.env) {
this.initHandler(false);
}
Expand Down Expand Up @@ -221,6 +219,8 @@ export class DefaultTicker extends EventEmitter implements ITicker {
this.tickerHandler?.release();
this.tickerHandler = null;
this.lastFrameTime = -1;

application.global.hooks.onSetEnv.unTap('graph-ticker', this._handleGraphTick);
}

protected checkSkip(delta: number): boolean {
Expand Down Expand Up @@ -280,4 +280,8 @@ export class DefaultTicker extends EventEmitter implements ITicker {

this.emit('tick', delta);
};

protected _handleGraphTick = () => {
this.initHandler(false);
};
}
2 changes: 1 addition & 1 deletion packages/vrender-components/src/scrollbar/scrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export class ScrollBar extends AbstractComponent<Required<ScrollBarAttributes>>
* 浏览器上的事件必须解绑,防止内存泄漏,场景树上的事件会自动解绑
*/
super.release(all);
(vglobal.env === 'browser' ? vglobal : this.stage).addEventListener('touchmove', this._handleTouchMove, {
(vglobal.env === 'browser' ? vglobal : this.stage).removeEventListener('touchmove', this._handleTouchMove, {
passive: false
});
this._clearDragEvents();
Expand Down
4 changes: 4 additions & 0 deletions packages/vrender-core/src/core/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,10 @@ export class Stage extends Group implements IStage {
this.window.release();
this._ticker?.remTimeline(this?.timeline);
this._ticker?.removeListener('tick', this.afterTickCb);
if (!this.params.ticker) {
// release stage创建的ticker,避免release外部的ticker
this._ticker?.release();
}
this.renderService.renderTreeRoots = [];
}

Expand Down
Loading