Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How do i remove a mesh from memory that was created by the combineMesh script?

Discussion in 'Scripting' started by kurylo3d, Nov 16, 2011.

  1. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,121
    For performance reasons i often combine a whole lot of meshes together... and it happens often and it changes often. It works great, but my problem now is i realize that each time i do it .. it adds to the total vram used. It says so in unity and it will crash my android app after about 30 combines... So....

    The question now is how do i remove a mesh from memory that was created by the combineMesh script?

    I have tried using destroyImmediate() on the gameobject that houses the mesh filter... i have even went and did something like this on the mesh in the mesh filter.....

    "if (currentNode.GetComponent<MeshFilter>())
    {
    Mesh mesh = currentNode.GetComponent <MeshFilter>().mesh;
    DestroyImmediate(mesh);
    }

    DestroyImmediate(currentNode);

    "

    So what am i missing? Why do i continue to add to the VRAM usage until i run out?
     
  2. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,121
    Just realize it also adds to the VBO Total ....

    My only assumption is that im creating meshes that arent being removed from memory when im done with them.... Am I wrong? What do i do?
     
  3. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,121
    I have tried using...
    "DestroyImmediate(mesh, true);"
    and
    " DestroyImmediate(mesh, false);"

    neither make any difference...
     
  4. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,121
    well i managed a workaround which is kind of an annoying workaround, but for now i am using "Resources.UnloadUnusedAssets()"

    And that removes stuff from the memory, but still I would love to know why the mesh doesnt get destroyed when i try... anyone know?
     
    nguyenqphan likes this.
  5. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,121
    The below code is the answer I have been looking for. instead of <MeshFilter>().mesh; im using <MeshFilter>().sharedMesh;

    "if (currentNode.GetComponent<MeshFilter>())
    {
    Mesh mesh = currentNode.GetComponent <MeshFilter>().sharedMesh;
    DestroyImmediate(mesh, tue);
    }

    DestroyImmediate(currentNode);

    "
     
    GLeBaTi, nguyenqphan and arnoob like this.
  6. rumanwork

    rumanwork

    Joined:
    Dec 7, 2012
    Posts:
    1
    Thank you, my good man!
     
  7. joel_b

    joel_b

    Joined:
    May 23, 2013
    Posts:
    4
    Great!
     
  8. Yang-Pil-Sun

    Yang-Pil-Sun

    Joined:
    May 10, 2013
    Posts:
    1
    Thanks hero!
     
  9. Dante_CyberdeckGames

    Dante_CyberdeckGames

    Joined:
    Mar 14, 2015
    Posts:
    4
    I know this is an older thread, just want to say thank you, as I was building up a lot of memory from unused meshes and this thread saved the day!
     
    nguyenqphan likes this.
  10. GLeBaTi

    GLeBaTi

    Joined:
    Jan 12, 2013
    Posts:
    41
    Thanks!)
     
  11. MoribitoMT

    MoribitoMT

    Joined:
    Jun 1, 2013
    Posts:
    293
    DestroyImmediate(mesh, true), is this destroys asset permenantly from project ?