Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by Bovine · Aug 24, 2012 at 11:08 AM · meshprofilercacheleakram

Am I leaking Mesh components or does Unity Cache Meshes between scenes?

Hi There

I was disturbed to see that moving between levels of our game (back and forth between two levels) and without changing anything, without saving or changing the number of meshes, that mesh count increases by two moving from one level to the next and the RAM used by meshes also increases level to level.

Firstly I am surprised to find that after calling Resources.UnloadUnusedAssets() having loaded a completely different level, if I call Resources.FindObjectsOfTypeAll() that all the meshes from the previous level are still loaded. Is Unity caching these? Certainly the mesh count goes up by only 2, far fewer than in the scenes concerned, but the mesh RAM is going up by either 5.1 or 5.4 MB, consistently, bar the slight fluctuation in the amounts.

While I can call Resources.FindObjectsOfTypeAll() and I think identify which Mesh are being added, I can't think of an easy way to find these meshes.

Note that the metrics I am observing are when connecting to a remote player - either iPhone or OSX Desktop player.

None of the meshes are marked DontDestroyOnLoad() but even so, it is hard to discover which meshes are being affected and as I am moving between levels, I cannot see by any visual inspection, that I am getting duplicates.

Cheers Bovine

Comment
Add comment · Show 2
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 DESTRUKTORR · Aug 24, 2012 at 11:33 AM 0
Share

I haven't come across this issue, but I'd be interested to see what's causing it, so I can avoid this problem... seems rather nasty, given how far out of your way you're going for garbage collection... are you using JS or C#, just out of curiosity?

avatar image Bovine · Aug 24, 2012 at 11:35 AM 0
Share

I'm using C#, our levels are quite large, especially for an iOS game. I am doing a plain vanilla test swapping between some very, very simple scenes.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bovine · Aug 24, 2012 at 01:02 PM

My simple test moving between two scenes - the mesh count and RAM is entirely predictable. Which means it must be me, or more accurately, it means that the save game system I am using is hanging onto mesh references.

It possibly explains another leak too.

Comment
Add comment · Show 3 · Share
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 Memige · Oct 26, 2012 at 08:53 PM 0
Share

While I admire the willingness to blame yourself, this doesn't actually answer your question. I too am having this same problem, and I do not have any save game functionality. I can consistently see my mesh count increase at run time every time I load a level. Happening in Editor, on PC, using C#. One unique behavior I've noticed is I have some objects that are deactivated by default, and I toggle them on/off as needed during game play. If I change the logic so everything is active at start, and then deactivate the things I don't need at run time, the leaked mesh problem does not happen(Though everything is visible for a second at load and looks terrible). If I change it back to be deactivated by default, then the leaked mesh problem returns. This is 100% reproducible. I can easily query the meshes in script and find all of them, but, as there is no way to get the object a mesh is associated with, I can't find them in the scene, nor discover where they came from.

avatar image Memige · Nov 06, 2012 at 12:04 AM 0
Share

Interesting. Certainly confirms the behavior I'm seeing. Unfortunately the link you gave appears to be broken, but I am looking into the work around you mentioned to see what I can figure out.

avatar image Bovine · Nov 06, 2012 at 12:13 AM 0
Share

Accidentally deleted the post... the link was to the save system use, Unity Serializer but I can't figure out why it won't work - seems Unity Answers is adding a trailing character encoding, perhaps a space?... anyone I edited the link, maybe it'll work now, otherwise remove anything after .com and manually go to the serializer.

That said, unless you're using it too it's not likely to help you - I was documenting the system I was using.

If you're calling Resources.FindObjectsOfTypeAll() anywhere, perhaps passing typeof($$anonymous$$esh) in as a parameter, then you maybe suffering a similar problem if you're caching every mesh returned by same.

if you're NOT calling this, then you might want to consider calling it and seeing if your mesh count is going up.

Note that if you're running in the editor the profiler metrics (and I think the above method) will return editor objects as well, so use carefully and of course, the numbers returned might not be an accurate reflection of the real world

Original post below.... .......

Hi There

I can't recall the details, but essentially the save game system we're using was caching everything in the scene, but despite the fact that the cache was cleared between levels, the Combine$$anonymous$$eshes created, I believe as part of static batching, are retained between levels and 'leak' so going from one level to the next and back, I would have two copies of all statically batched stuff from the first level being entered twice and 1 copy from the 2nd level.

On memory sparse devices like the 3GS this rapidly becomes a huge problem as I can be leaking 5+$$anonymous$$B between levels.

$$anonymous$$y solution, was to not add the combined meshes to the cache and in fact the Unity Serializer we use now has a filter delegate $$anonymous$$ike added so we could disable this (http://whydoidoit.com).

I can't say for sure whether this is a Unity bug or a bug in $$anonymous$$ike's code, but when I encountered it, it certainly looked like the former.

One irritating thing, is that these combined static meshes have a negative id on the PC but a positive one on iOS and so the only way to tell is to look the name of the mesh, which, if it contains 'Combined $$anonymous$$esh' is one of the offending meshes and we don't put that anywhere!

Perhaps that will help? GL.

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Profiler shows Object.ElementAddr_3_8() called over a million times. What is it? How do I reduce this? 1 Answer

Mesh SubmitVBO Taking Up CPU Power 1 Answer

Universal 10 memory leak, blank scene 0 Answers

Font.CacheFontForText is 87.3% in the profiler and causes a HUGE lag spike 1 Answer

Unity Renders objects that are not in build - Bug? 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