How to remove and remove all child geometry and meshes from an Object3D object?

In this project, I work on the fact that I got several Collada models, and then removed when they are no longer needed. There seems to be a memory leak somewhere in the project, and I'm looking for ways to make it work as smoothly as possible, since time is not on my side ... I feel like I am not deleting the grids correctly and that this can cause some memory leaks, which I have.

I load objects using LoadObject(level_1_character, "Assets/Level_1_Character.dae"); , for example, where level_1_character is Object3D. This calls the following function:

 function LoadObject(name, url) { var mesh, geometry, material, animation; var loader = new THREE.ColladaLoader(); loader.options.convertUpAxis = true; loader.load(url, function(col) { mesh = col; geometry = col.scene; name.name = url.toString(); name.add(geometry); }); } 

I add objects to the scene depending on the level through scene.add(level_1_character); , and then delete it by following these steps:

 level_1_character.traverse(function(child){ if (child instanceof THREE.Mesh) { child.material.dispose(); child.geometry.dispose(); } }); 

I'm not sure if this really removes the object completely. It seems that objects are still present in memory. Any idea what I'm doing wrong here?

+5
source share

Source: https://habr.com/ru/post/1214182/


All Articles