question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Editor: Memory leak when loading 4096x4096 texture several times

See original GitHub issue

Describe the bug

I tried to edit the MaterialsVariantsShoe.glb file from the KhronosGroup git in the editor and changed the normalMap and aoMap textures several times to a 4096x4096 texture.

I could use the same texture several times and the memory starts to increase after ~9-10 times (in my tests the value of changes sometimes were even smaller). That causes the webgl context to crash after enough changes.

To Reproduce

Steps to reproduce the behavior:

  1. Go to ThreeJS Editor
  2. Import MaterialsVariantsShoe.glb
  3. Change material to MeshPhysicalMaterial
  4. Set the normalMap / aoMap >10 times to a 4096x4096 texture
  5. The leak begins to grow after every following change

Expected behavior

After my analysis this only happens in 64bit browsers. The following lines of WebGLState.js causes the increasment.

function texImage2D() {

	try {

		gl.texImage2D.apply( gl, arguments ); //After this function call the memory was increased highly and is only freed after closing or reloading the tab / browser.

	} catch ( error ) {

		console.error( 'THREE.WebGLState:', error );

	}

}

Screenshots

After 30 changes with the same texture:

Browser Taskmanager Image
Vivaldi 32bit image
Vivaldi 64bit image
Chrome 32bit 32bit_30times
Chrome 64bit 64bit_30times

Platform:

  • Device: [Desktop, Mobile]
  • OS: [Windows, Android, IPadOS]
  • Browser: [Chrome, Canary Chrome, Firefox, Safari, Edge, Opera, Vivaldi, Opera GX, Chrome for Android]
  • Three.js version: r117 - r124

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Mugen87commented, Jan 27, 2021

Can you please call Texture.dispose() every time you replace an existing texture? Meaning:

if ( child.material.aoMap !== null ) child.material.aoMap.dispose();
child.material.aoMap = texture;
1reaction
RealTecWarecommented, Jan 26, 2021

I’m able to crash the webgl context with this, after the memory is over ~8GB (set the normalMap ~90-100 Times in my test).

context_lost

Read more comments on GitHub >

github_iconTop Results From Across the Web

High Memory usage when using 4096x4096 textures (4k ...
As for the Memory, looking at the profiler, all references textures loaded, and even though for example boss is not active, all the...
Read more >
Is there an editor memory leak?... - Unreal Engine Forums
Hi After working on any level in the editor for any length of time, I start to get the 'texture streaming pool over...
Read more >
My Maya 2015 SP5 seems to be leaking memory (allocating 100mb ...
I'm using Maya 2015 SP5, I have a simple model that has a 4096x4096 Tiff (layer uncompressed) texture attached to a Blinn. After...
Read more >
Memory leak caused loading textures, despite calling ...
Here, I've created the new texture, and loaded it using the texture class' load function. The textures render absolutely fine, but the loading...
Read more >
Lifecycle of a Texture in Unreal Engine for Virtual Production
If all those polys and texture pixels add up to more memory than you have available to ... And a lot of times...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found