RangeError: WebAssembly.Memory(): could not allocate memory

I updated the three.module.js to the new release 142 and I am getting an error “RangeError: WebAssembly.Memory(): could not allocate memory”?

The error occurs when I try to cross the bridge on a chrome browser and not on other browsers.

Have you checked your actual physical memory consumption?

I’m seeing very similar errors

when trying to load/process more DEM-tiles (digital elevation model) than my physical memory can hold.

your engine probably needs to load additional data for the other side of the bridge.

I tried the older versions of threejs cannon projects it also gets the same error, Its not threejs error, it chrome bug

Is there anyway we can programmatically increase the browser’s allocated memory so we can load more 3d assets, creating threejs cannon seems to be limited by the browser allocated memory, is there a way around this?

In my experience (macOS 10.15.7, Google Chrome Version 103.0.5060.53) memory does already get allocated dynamically.
The first screenshot shows the ranking of memory “consumers”, immediately following a reboot:

And this is after loading my application which tries to load more data than my physical memory (32 GB) can accomodate. Taken around the time I see the first of the error messages in the console as in my previos post:

Note, that “memory in use” plus “files in cache” pretty much amounts to the available physical memory of 32 GB. In the process list, Google Chrome accounts for ≈ 16 GB of those.

1 Like

use firefox or opera browser, chrome browser is not efficient on memory and often crashes, you can observe chrome high cpu and ram usage on the rask manager even with data processing social media websites.

Is there a javascript api or class that could increase the chrome browser allocated memory so that THREEjs wouldn’t crash?

No, something like this does not exist.

Not a Unity fan here, but this memory comsuption / limit is what has made Unity pause and defer several times webGL publishing using exclusively webAssembly, and until today remains a bottleneck for all of us to really consider it - has stopped me at least. It is not that webAssembly cannot be used, it is just web browsers are not there yet

1 Like

I tried all tricks to push THREEjs project to the limit by automatically discarding variables and manages the scene by removing the geometries and textures when the character gets far from the object and loading only the object near, but these isn’t enough, I hope someday Chrome or a new version of JavaScripts allows memory allocation management.

I have just updated the three.module.js with the new release 145 and suddenly the rendering get smoother and the browser crashing disappears, it still crashed after a while (of abusing the game) but it prolonged the occurrence of the browser memory allocation error

The out of memory error is caused by accumulating textures, I found that even after you have removed the geometries and materials the textures stays, you can observe at the renderer.infor.memory. I fixed the out of memory error by targeting each textures when disposing the materials.

// ==== MEMORY MANAGEMENT ====
// Dispose hierarchy
window.disposeHierarchy=function(node){
	engineParameters.scene.remove(node)
	sceneTraverse(node,dO0=>{
		if(dO0.geometry)dO0.geometry.dispose()
		if(dO0.material){
			if(dO0.material.length){
				for(processMemory.hD0=0;processMemory.hD0<dO0.material.length;++processMemory.hD0)disposeResources(dO0.material[processMemory.hD0])
			}else disposeResources(dO0.material)
		}
		dO0=undefined
	})
	engineParameters.renderer.renderLists.dispose()
	node=undefined
}
// Scene traverse
const sceneTraverse=(obj,fn)=>{
	if(!obj)return
	fn(obj)
	if(obj.children&&obj.children.length>0){
		obj.children.forEach(o=>{
			sceneTraverse(o,fn)
		})
	}
	obj=fn=undefined
}
// Dispose resources
function disposeResources(mtrl){
	if(mtrl.alphaMap){
		mtrl.alphaMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.alphaMap.source.uuid))
	}
	if(mtrl.aoMap){
		mtrl.aoMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.aoMap.source.uuid))
	}
	if(mtrl.blendDstAlpha){
		mtrl.blendDstAlpha.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.blendDstAlpha.source.uuid))
	}
	if(mtrl.blendEquationAlpha){
		mtrl.blendEquationAlpha.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.blendEquationAlpha.source.uuid))
	}
	if(mtrl.blendSrcAlpha){
		mtrl.blendSrcAlpha.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.blendSrcAlpha.source.uuid))
	}
	if(mtrl.bumpMap){
		mtrl.bumpMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.bumpMap.source.uuid))
	}
	if(mtrl.displacementMap){
		mtrl.displacementMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.displacementMap.source.uuid))
	}
	if(mtrl.emissiveMap){
		mtrl.emissiveMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.emissiveMap.source.uuid))
	}
	if(mtrl.envMap){
		mtrl.envMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.envMap.source.uuid))
	}
	if(mtrl.lightMap){
		mtrl.lightMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.lightMap.source.uuid))
	}
	if(mtrl.map){
		mtrl.map.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.map.source.uuid))
	}
	if(mtrl.metalnessMap){
		mtrl.metalnessMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.metalnessMap.source.uuid))
	}
	if(mtrl.normalMap){
		mtrl.normalMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.normalMap.source.uuid))
	}
	if(mtrl.roughnessMap){
		mtrl.roughnessMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.roughnessMap.source.uuid))
	}
	if(mtrl.specularMap){
		mtrl.specularMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.specularMap.source.uuid))
	}
	if(mtrl.gradientMap){
		mtrl.gradientMap.dispose()
		engineParameters.scene.remove(engineParameters.scene.getObjectById(mtrl.gradientMap.source.uuid))
	}
	mtrl.dispose()
	mtrl=undefined
}

After adding the scene.remove(scene.getObjectById(material.gradientMap.source.uuid)) on each material maps, the out of memory error disappears and I can play without having been interrupted by out of memory error.

2 Likes