mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-26 19:54:30 +08:00
fix: 画布内存泄漏
This commit is contained in:
1 parent
351ede3996
commit
65855d1a64
13 files changed
+50
-30
No files matched your search
@@ -24,7 +24,8 @@ export class MotaOffscreenCanvas2D extends EventEmitter<OffscreenCanvasEvent> {
|
||||
|
||||
/**
|
||||
* 创建一个新的离屏画布\
|
||||
* **注意**:如果你在自定义渲染元素中使用,请避免使用此构造函数,而应该使用 `RenderItem.requireCanvas`
|
||||
* **注意**:如果你在自定义渲染元素中使用,请避免使用此构造函数,而应该使用 `RenderItem.requireCanvas`,
|
||||
* 之后如果不使用,再使用 `RenderItem.deleteCanvas` 删除。
|
||||
* @param alpha 是否启用透明度通道
|
||||
* @param canvas 指定画布,不指定时会自动创建一个新画布
|
||||
*/
|
||||
|
||||
@@ -348,10 +348,10 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
|
||||
/** 这个渲染元素使用到的所有画布 */
|
||||
protected readonly canvases: Set<MotaOffscreenCanvas2D> = new Set();
|
||||
/** 这个渲染元素每个画布的配置信息 */
|
||||
private readonly canvasMap: Map<
|
||||
private readonly canvasMap: WeakMap<
|
||||
MotaOffscreenCanvas2D,
|
||||
RenderItemCanvasData
|
||||
> = new Map();
|
||||
> = new WeakMap();
|
||||
//#endregion
|
||||
|
||||
//#region 交互事件
|
||||
@@ -1305,6 +1305,14 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
|
||||
this.emit('destroy');
|
||||
this.removeAllListeners();
|
||||
this.canvases.clear();
|
||||
this.cache.clear();
|
||||
this.propagationStoped.clear();
|
||||
this.cachedEvent.clear();
|
||||
this.mouseId.clear();
|
||||
this.touchId.clear();
|
||||
this.children.clear();
|
||||
this._root = void 0;
|
||||
this._parent = void 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user