Jump to content

dispose Mesh and ram release


efxlab
 Share

Recommended Posts

Hello,

I load a Glft model with a loader

https://bin.fuelphp.com/snippet/view/OI

and later with a HTML button I change the model in the same scene with a dispose (to remove it) and reload the new.

The issue is that it seem memory is not released from the previous model, on iPad tablet for exemple, the scene become very slow. After several disposes and loads safari crash out of memory.

Maybe Am I wrong with the mesh capture :

loader.onMeshLoaded = function (mesh) {
            
            actualMesh = mesh;
};

any idea ?

Link to comment
Share on other sites

I guess this is because your gltf is loading multiple mesh so you have to keep a list of them

In your case you are storing only the last one

You can call scene.debugLayer.show() to get an UI to get the list of meshes

Link to comment
Share on other sites

Hey, it fine now for mesh release, but for Material ? I see in debug that at each load it store material in memory on a new GLFT load, How I can access and dispose ?

I use GLFT format so its PBRMaterial ? I tried that but it no work :

for(var i=0, len=activeMeshes.length; i < len; i++){
                activeMeshes.dispose();
               activeMeshes.PBRMaterial.dispose();
 }

How I can access to PBRMaterial from a GLFT loader ?

thanks

 

Ok on loader I can access to materials :

loader.onMaterialLoaded = function (material) {
 };

 

Link to comment
Share on other sites

Hi efxlab !

BABYLON.Mesh has no attribute PBRMaterial but a single attribute material to deal with StandardMaterial and PBRMaterial.
You can get material directly this way and dispose it (it will dispose the material only)


Moreover, there is parameters in the method dispose of Material to force disposing its textures.
The same way, there is parameters in the method dispose of Mesh to dispose its material (if exist) as well.

Here is a PG showing these 2 solutions : https://www.babylonjs-playground.com/#10D6YT#77
With solution 1, textures are still in memory.
With solution 2, disposing meshes cleans also all the now unnecessary data.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...