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 htaunay · Dec 08, 2011 at 05:27 PM · profilergarbage-collectiongcgc.collect

Gc.Collect locations on the Profiler

When using the Unity3d profiler, I can't help but notice the recurring GC spikes. This topic has been exhaustively discussed on unityAnswers, of that I am aware.

What I have my doubts about is the relevance of WHERE the GC.collect() appears. In other words, if the GC.collect() method appears as a child of another function, does that mean that such parent function is generating a considerable amount of garbage? Or does it mean that the GC's heap got full and GC.collect() just so happened to be called inside a given parent function?

Since I am here, another fact that I am curious about : is it possible to occur more than one call of GC.collect() in the same frame, maybe even as parallel processes?

Any help is welcome, thanks in advance!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Keryu · Dec 08, 2011 at 07:49 PM

In the profiler, be sure your view is set to 'GroupHierachy'. This can be found right above the list of functions and the time it takes to complete each one.

If there was a garbage collection on the frame you are viewing, you should see a GarbageCollection section under the list of functions. Expand it to see any collections that happened during that frame. I've never seen Garbage collection be listed under another function. (Note: I can never find GC.Collect() or GarbageCollection in the list if I'm set to 'Hierarchy' view. Perhaps others have?)

For a vast majority of your frames, you shouldn't be able to find a GarbageCollection. An easy way to test this is to call GC.Collect() on one of your script's Awake() function. If you run the profiler and view the first frame, you should see a GarbageCollection section. Note that it does not show up under your script's Awake() function. If you go to a different frame, though, the garbage collection details will not show up (unless you had a garbage collection take place that frame).

As for if more than one collection can take place in the same frame, that I am unsure of. I would guess that only one collection would call in a single frame, but I cannot answer that with certainty.

Also, on the off chance that you are developing for iOS, I would strongly recommend the internal profiler. You can review the log after playing your game to see when the garbage collector called and how long it took. I have found it much more convenient than the editor profiler. iOS Internal Profiler

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 htaunay · Dec 09, 2011 at 12:39 PM 0
Share

Thanks for the response $$anonymous$$eryu!

$$anonymous$$y question was mainly inspired because I often see CG.Collect calls in the "Hierarchy" view, but for some reason it appears under different parent functions during each call. $$anonymous$$aybe I didn't make myself clear, but I never witnessed a CG.Collect call at the root of the "Hierarchy" view, differently from the "GroupHierarchy" view. What made me curious was the "why" of the varying parent functions in the "Hierarchy" view in the Profiler. Are these parent functions generating most of the garbage (which would be good, because it would serve as a tip to where to start my optimizations), or did CG.Collect just happen to be called while the given parent function was executing?

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

Firebase garbage collection bug, trigger GC manually ? ,Firebase garbage collection bug, trigger GC manually 0 Answers

Why is GC.Collect() very slow? 2 Answers

What causes an increase in editor GUI garbage collection? 2 Answers

Mono profiler hooking on Unity 2 Answers

CPU being choked by GC.MarkDependencies 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