Skip to content

Commit

Permalink
If you make rommel, you clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterlucas committed Apr 20, 2023
1 parent b17b3a5 commit c988a62
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/platforms/browser/ImageWorker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export default class ImageWorker {
if (this._worker) {
this._worker.terminate();
}

this._items = null;
this._worker = null;

delete this._items;
delete this._worker;
}

_initWorker() {
Expand Down
6 changes: 6 additions & 0 deletions src/platforms/browser/WebPlatform.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ export default class WebPlatform {
if (this._imageWorker) {
this._imageWorker.destroy();
}

clearInterval(this._loopHandler);

this._removeKeyHandler();
this._removeClickHandler();
this._removeHoverHandler();
this._removeScrollWheelHandler();
this._removeVisibilityChangeHandler();

this.stage = null;
delete this.stage;
}

startLoop() {
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/c2d/C2dRenderer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export default class C2dRenderer extends Renderer {

destroy() {
this.tintManager.destroy();

this.tintManager = null;
delete this.tintManager;
}

_createDefaultShader(ctx) {
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/c2d/C2dTextureTintManager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default class C2dTextureTintManager {

destroy() {
this.gc(true);

this.stage = null;
delete this.stage;
}

_addMemoryUsage(delta) {
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/webgl/WebGLCoreRenderExecutor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export default class WebGLCoreRenderExecutor extends CoreRenderExecutor {
super.destroy();
this.gl.deleteBuffer(this._attribsBuffer);
this.gl.deleteBuffer(this._quadsBuffer);

this.gl = null;
delete this.gl;
}

_reset() {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/webgl/WebGLRenderer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export default class WebGLRenderer extends Renderer {

destroy() {
this.shaderPrograms.forEach(shaderProgram => shaderProgram.destroy());

this.shaderPrograms = null;
this._compressedTextureExtensions = null;

delete this.shaderPrograms;
delete this._compressedTextureExtensions;
}

_createDefaultShader(ctx) {
Expand Down
19 changes: 18 additions & 1 deletion src/renderer/webgl/WebGLShaderProgram.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class WebGLShaderProgram {
this.fragmentShaderSource = fragmentShaderSource;

this._program = null;
this.gl = null;

this._uniformLocations = new Map();
this._attributeLocations = new Map();
Expand Down Expand Up @@ -109,8 +110,24 @@ export default class WebGLShaderProgram {
destroy() {
if (this._program) {
this.gl.deleteProgram(this._program);
this._program = null;
}

this._attributeLocations = null;
this._currentUniformValues = null;
this.fragmentShaderSource = null;
this._program = null;
this.gl = null;
this._uniformLocations = null;
this.vertexShaderSource = null;

delete this.vertexShaderSource;
delete this._program;
delete this._currentUniformValues;
delete this.fragmentShaderSource;
delete this.gl;
delete this._uniformLocations;
delete this._attributeLocations;

}

get glProgram() {
Expand Down
14 changes: 14 additions & 0 deletions src/tree/Stage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ export default class Stage extends EventEmitter {
this.ctx.destroy();
this.textureManager.destroy();
this._renderer.destroy();

this.gl = null;
this.c2d = null;
this.ctx = null;
this.platform = null;
this.textureManager = null;
this._renderer = null;

delete this.gl;
delete this.c2d;
delete this.ctx;
delete this.platform;
delete this.textureManager;
delete this._renderer;
}

stop() {
Expand Down
5 changes: 5 additions & 0 deletions src/tree/TextureThrottler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export default class TextureThrottler {
destroy() {
this._sources = [];
this._data = [];
this.stage = null;

delete this._sources;
delete this._data;
delete this.stage;
}

processSome() {
Expand Down
15 changes: 15 additions & 0 deletions src/tree/core/CoreContext.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ export default class CoreContext {
destroy() {
this._renderTexturePool.forEach(texture => this._freeRenderTexture(texture));
this._usedMemory = 0;

this.stage = null;
this.root = null;

this.renderState = null;
this.renderExec = null;
this._renderTexturePool = null;
this._zSorts = null;

delete this.stage;
delete this.root;
delete this.renderState;
delete this.renderExec;
delete this._renderTexturePool;
delete this._zSorts;
}

hasRenderUpdates() {
Expand Down
7 changes: 7 additions & 0 deletions src/tree/core/CoreRenderExecutor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export default class CoreRenderExecutor {
}

destroy() {
this.ctx = null;
this.renderState = null;
this.gl = null;

delete this.ctx;
delete this.renderState;
delete this.gl;
}

_reset() {
Expand Down

0 comments on commit c988a62

Please sign in to comment.