Skip to content

Commit

Permalink
fixed ImageBitmap memory leak (#3399)
Browse files Browse the repository at this point in the history
* fixed ImageBitmap memory leak

* better naming
  • Loading branch information
elalish authored May 2, 2022
1 parent 8e0894b commit 4734ba3
Show file tree
Hide file tree
Showing 8 changed files with 1,164 additions and 910 deletions.
265 changes: 137 additions & 128 deletions package-lock.json

Large diffs are not rendered by default.

688 changes: 389 additions & 299 deletions packages/model-viewer/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/model-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"@types/chai": "^4.2.21",
"@types/mocha": "^8.2.3",
"@types/pngjs": "^6.0.1",
"@types/three": "^0.137.0",
"@types/three": "^0.139.0",
"@ungap/event-target": "^0.2.2",
"chai": "^4.3.4",
"focus-visible": "^5.2.0",
Expand All @@ -104,4 +104,4 @@
"publishConfig": {
"access": "public"
}
}
}
3 changes: 2 additions & 1 deletion packages/model-viewer/src/test/model-viewer-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const setupLighting =
// TODO(sun765): this only test whether the screenshot
// is colorless or not. Replace this with more robust
// test in later pr.
function testFidelity(screenshotContext: WebGLRenderingContext) {
function testFidelity(screenshotContext: WebGLRenderingContext|
WebGL2RenderingContext) {
const width = screenshotContext.drawingBufferWidth;
const height = screenshotContext.drawingBufferHeight;

Expand Down
10 changes: 7 additions & 3 deletions packages/model-viewer/src/three-components/GLTFInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ export class GLTFInstance implements GLTF {
materials.forEach(material => {
// Explicitly dispose any textures assigned to this material
for (const propertyName in material) {
const propertyValue = (material as any)[propertyName];
if (propertyValue instanceof Texture) {
propertyValue.dispose();
const texture = (material as any)[propertyName];
if (texture instanceof Texture) {
const image = texture.source.data;
if (image instanceof ImageBitmap) {
image.close();
}
texture.dispose();
}
}
material.dispose();
Expand Down
76 changes: 38 additions & 38 deletions packages/modelviewer.dev/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4734ba3

Please sign in to comment.