Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Bug About Mesh object from MeshFilter.mesh is not destroyed.

Discussion in 'Editor & General Support' started by junimnjw, May 30, 2023.

  1. junimnjw


    Apr 18, 2022
    I am using MeshFilter.mesh property in my script.
    my problem is when I get the property value , I can see the number of mesh object increases continously when I run the same logic..
    I checked the gameboject that holds the MeshFilter component was successfully destoryed.. but the mesh object was still not destoryed.. is there any way to avoid the leak issue?
  2. spiney199


    Feb 11, 2021
    returns an instance (copy) of the mesh when you access it. Accessing it multiple times is going to make multiple copies, and as these are
    , they are managed objects you need to destroy when no longer needed.

    Usually you access the property once to get that instance, and destroy the instance when no longer needed.

    Best to refer to the docs for this sort of thing:
  3. Kurt-Dekker


    Mar 16, 2013
    Adding onto Spiney's excellent post...

    Usually the use cases are things like:

    - you have different meshes you want to assign, so you keep those Mesh references in your code and assign them to the MeshFilter when needed

    - you have different geometry (verts, tris, etc.), so you keep those arrays and feed them into the Mesh instance that you retrieved (or created!) and assigned to the MeshFilter

    What exactly is your use case for manipulating meshes?

    If you want more procgen examples, have a look around my MakeGeo project.

    MakeGeo is presently hosted at these locations: