Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Habowski · Apr 13, 2016 at 11:36 AM · meshmemorymemory managementmemory-leakunloading

Unity not unloading procedurally generated mesh when parent GameObject is destroyed and its not referenced

I've seen this pop up a number of times but haven't seen a definitive answer (here, here, here, etc). In my case I'm simply generating a mesh, attaching it to a gameobject, and when it comes time I destroy that gameobject, nothing too special.

However, I noticed in the memory profiler the meshes weren't actually being unloaded and memory would accumulate forever. I've tried every unload method I could find but nothing works except Resources.UnloadUnusedAssets(). But I feel like you really shouldn't have to call that almost every frame and there should be some way to unload the mesh properly.

As you can see in the attached picture there aren't even any references to these meshes so why are they sticking around? Furthermore, I also call .clear() on every mesh that I attempt to destroy but you can see in the pic they are still just as large as the other proper meshes.

Some code snippets I've tried (in many different orders etc):

             if (chunk.GetComponent<Mesh>() != null) chunk.GetComponent<Mesh>().Clear();
             chunk.SetActive(false);
 
             SkinnedMeshRenderer.Destroy(chunk.GetComponent<Mesh>());
             SkinnedMeshRenderer.DestroyObject(chunk.GetComponent<Mesh>());
             GameObject.DestroyImmediate(chunk.GetComponent<Mesh>());
             AssetBundle.Destroy(chunk.GetComponent<Mesh>());
             Resources.UnloadAsset(chunk.GetComponent<Mesh>());
             GameObject.Destroy(chunk.GetComponent<Mesh>());
             GameObject.Destroy(chunk);
 
             SkinnedMeshRenderer.Destroy(chunk);
             SkinnedMeshRenderer.DestroyObject(chunk);
             GameObject.DestroyImmediate(chunk);
             AssetBundle.Destroy(chunk);
             Resources.UnloadAsset(chunk);
             GameObject.Destroy(chunk);


memory-profiler.png (22.9 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mitaywalle · Feb 07, 2018 at 02:36 PM 0
Share

$$anonymous$$esh isn't a component, you can't use GetComponent(). You can Destroy($$anonymous$$eshfilter.shared$$anonymous$$esh), it force object to unload, BUT other linked objects will disappear to

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Memory usage increase after a mesh rewrite??? 1 Answer

Mesh memory leak 3 Answers

0 or Blank Ref Count Items in Memory Profiler 0 Answers

Memory Allocation Continues to Grow? iOS. 4.6.3 0 Answers

Is this memory usage too much for a mobile game? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges