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
0
Question by larrykirschner · Sep 15, 2014 at 08:49 PM · memory leakroot

tools/techniques to find memory-leak roots in unity?

I'm running into memory-leak issues in a game project and having trouble identifying the cause[s].

In other garbage-collected platforms that I've worked on, memory-profiling tools can display a graph, so you can see the 'root' objects that are pinning other objects into memory.

Is there any way to view that type of graph/automate finding root memory objects in Unity?

In terms of env/platform, I'm using unity 4.5.2 and MonoDevelop as the IDE. The target platform is iOS, but the memory issue presents in the Unity editor as well.

Additional detail: there seems to be a variety of objects incorrectly pinned in memory, but the big-ticket problems are textures associated with Resource-loaded prefabs.

Not having a profiler that identifies memory roots, I've been doing the following:

1) For all scene transitions, I have a bumper scene that calls Resource.UnloadAllUnusedAssets and waits for that to complete. Once resource unload completes, it also calls GC.Collect before proceeding with the scene change.

2) I've checked for static properties/singletons are not holding references to zombie objects or assets and haven't found anything there 3) I've checked for anything that survives a scene load and is registered to any event and haven't found anything there 4) (in Unity Editor) I've tried forcing my bumper scene to never load the next scene, and then deleted all objects off the scene graph/hierarchy and triggered additional calls to Resources.UnloadAllUnusedAssets

...so far no luck.

Any help would be greatly appreciated, especially if it's "here's how you can view a memory graph for Unity"

Thanks, Larry

Comment
Add comment · Show 4
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 Stormizin · Sep 15, 2014 at 08:53 PM 0
Share

Did you tryied to search about performance tracker? Unity have a tool for you to check the CPU, $$anonymous$$emory, Disk work and other things to help you get performance with your project

avatar image larrykirschner · Sep 15, 2014 at 09:01 PM 0
Share

@stormzin,

I can see in the unity profiler what's stuck in memory. It also gives you a reference count. What's missing is a memory graph. Without a memory graph, it seems to me like memory leaks are a needle-in-a-haystack type problem.

avatar image larrykirschner · Sep 15, 2014 at 10:53 PM 0
Share

I couldn't find a way to get a memory graph for Unity but I was able to fix the memory leak. The cause seems to have been related to my having a prefab assigned to an FsmGameObject variable in a Play$$anonymous$$aker fsm that was loaded as a resource.

I'm not sure why that would cause leak behavior, but taking that prefab away from playmaker seems to have fixed everything.

Anyone ever run into odd memory-leak issues with Play$$anonymous$$aker?

avatar image smoggach · Sep 15, 2014 at 11:53 PM 0
Share

I've never run into memory leak issues with Play$$anonymous$$aker. How'd you manage to set a prefab as a game object variable in playmaker? I would assume it would have to instantiate the prefab? or is it a prefab instance? I'd recommend avoiding playmaker for anything but simple statemachines and prototyping.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by smoggach · Sep 16, 2014 at 12:05 AM

Here are some tips:

Resources.UnloadUnusedAssets will hunt down any assets still in memory that aren't referenced by anything and unload them. The key thing here is that they must not be referenced. You shouldn't call this unless you're gearing up to load a lot of stuff and don't require a decent framerate or user input for the next few frames. Unity will do a nice job of garbage collection on it's own as long as you remember to set things to null when you're done with them.

As for unity's profiler: Click on the memory section, click where it says "simple" down where the information is displayed and change it to "detailed". Then click "take snapshot".

This gives you a snapshot of everything loaded into memory at that particular frame and the things that reference it. From here you can look at each one and make sure you know why it's there, or go through really fast and look for things with lots of references.

You will have a much easier time of finding leaks if you name everything that you create at runtime (so it's easier to distinguish in the profiler).

Using a Sprite as an example:

Comment
Add comment · Show 1 · 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 meat5000 ♦ · Dec 20, 2014 at 03:32 PM 0
Share

@smoggach Your post here seems incomplete matey.

avatar image
0

Answer by Saddamjit_Singh · May 03, 2016 at 01:54 PM

Here is what you can do-

1.Check for foreach and while loops in update. 2.Use memory section of profiler.If leak is coming on phone you can run profiler for it also. 3.Set compression of textures to 16 bit if there are many textures in your game. 4.Use System.GC.Collect(). Use it with care because it can cause frequent hangs in game. 5.Use Resources.UnloadUnusedAssets(). 6.Use instruments in xCode.

Comment
Add comment · 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

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

26 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AR Foundation adding reference images at runtime causes memory leak on iOS, but works fine on Android. 0 Answers

Root Bone? Where? 1 Answer

Rigging Question: Location of Root bone 0 Answers

App crashing on Ipad - suspected memory leak. 1 Answer

Leaking GFX memory on iOS on LoadSceneAsync 0 Answers


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