Resolve memory leak when deleting a webgl layer
Various references were kept, preventing the layer and underlying renderer and webgl context to be garbage collected. Also, the Helper was simplified because it turns out deleting manually all Webgl objects is useless: these objects will be released when the context is garbage collected anyway. Note: this touches the Layer and BaseLayer classes, as the following were preventing the layer from being garbage collected: * layer reference in the `state_` object in BaseLayer * dangling listener for source change in Layer
This commit is contained in:
@@ -266,18 +266,6 @@ class WebGLHelper extends Disposable {
|
||||
*/
|
||||
this.bufferCache_ = {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Array<WebGLShader>}
|
||||
*/
|
||||
this.shaderCache_ = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Array<WebGLProgram>}
|
||||
*/
|
||||
this.programCache_ = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {WebGLProgram}
|
||||
@@ -419,18 +407,6 @@ class WebGLHelper extends Disposable {
|
||||
disposeInternal() {
|
||||
this.canvas_.removeEventListener(ContextEventType.LOST, this.boundHandleWebGLContextLost_);
|
||||
this.canvas_.removeEventListener(ContextEventType.RESTORED, this.boundHandleWebGLContextRestored_);
|
||||
const gl = this.getGL();
|
||||
if (!gl.isContextLost()) {
|
||||
for (const key in this.bufferCache_) {
|
||||
gl.deleteBuffer(this.bufferCache_[key].buffer);
|
||||
}
|
||||
for (const key in this.programCache_) {
|
||||
gl.deleteProgram(this.programCache_[key]);
|
||||
}
|
||||
for (const key in this.shaderCache_) {
|
||||
gl.deleteShader(this.shaderCache_[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -652,7 +628,6 @@ class WebGLHelper extends Disposable {
|
||||
const shader = gl.createShader(type);
|
||||
gl.shaderSource(shader, source);
|
||||
gl.compileShader(shader);
|
||||
this.shaderCache_.push(shader);
|
||||
return shader;
|
||||
}
|
||||
|
||||
@@ -684,7 +659,6 @@ class WebGLHelper extends Disposable {
|
||||
gl.attachShader(program, fragmentShader);
|
||||
gl.attachShader(program, vertexShader);
|
||||
gl.linkProgram(program);
|
||||
this.programCache_.push(program);
|
||||
return program;
|
||||
}
|
||||
|
||||
@@ -811,8 +785,6 @@ class WebGLHelper extends Disposable {
|
||||
*/
|
||||
handleWebGLContextLost() {
|
||||
clear(this.bufferCache_);
|
||||
clear(this.shaderCache_);
|
||||
clear(this.programCache_);
|
||||
this.currentProgram_ = null;
|
||||
}
|
||||
|
||||
@@ -823,8 +795,6 @@ class WebGLHelper extends Disposable {
|
||||
handleWebGLContextRestored() {
|
||||
}
|
||||
|
||||
// TODO: shutdown program
|
||||
|
||||
/**
|
||||
* Will create or reuse a given webgl texture and apply the given size. If no image data
|
||||
* specified, the texture will be empty, otherwise image data will be used and the `size`
|
||||
|
||||
Reference in New Issue
Block a user