• 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 bplunkett · Oct 03, 2013 at 05:38 PM · c#performanceprofilergarbage-collection

CPU being choked by GC.MarkDependencies

Hi y'all,

I was wondering if someone could help me out with an odd garbage collection behavior I'm seeing. I'm very new to Unity so forgive me if this ends up being dumb. We have a point in our project where the user can view what in our code ends up being a very large collection of objects (another player and all their assets). They can cycle through other players and each time they go to the next the previous one is unloaded. Going to the next causes a severe drop in the framerate and a huge CPU spike in the profiler that lasts for a few seconds and then goes away. Now, this sort of makes sense but what seems odd is that it's not GC.Collect that's causing the hit it's GC.MarkDependencies and it shows up in the profiler with the color for "other". I added an explicit call to GC.Collect after unloading the player that should complete before you could press the next button again but it didn't change the behavior at all. Any help on figuring out what's hijacking our CPU would be most appreciated.

Comment
Add comment · Show 7
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 Jamora · Oct 03, 2013 at 06:04 PM 0
Share

Never heard of GC.$$anonymous$$arkDependencies.. didn't even find it in the System.GC class. (I even peeked inside the decomplied mscorlib.)

Nevertheless, it sounds as if the actual creation of the objects causes the spike, so my first attempt would be to figure out a way to create as few objects on the heap as possible.

What does the code look like?

avatar image bplunkett · Oct 03, 2013 at 06:25 PM 0
Share

Yeah, I was surprised that $$anonymous$$arkDependencies didn't get any hits at all in Google. I know what it's doing in theory but it seems odd that it has to take the processor for that long.

I'm not sure about all the code since I'm very new to it but the gist of it is that the previous player and all of their many, many subobjects are despawned and a new one is immediately created. I'm sure that's the root of the problem but I'm not sure why the marking process should take so long.

avatar image Jamora · Oct 03, 2013 at 06:45 PM 0
Share

Are the Player's (sub)objects the same or at least similar? $$anonymous$$aybe you could make a Set method that takes in a new Player(sub)Object and ins$$anonymous$$d of destroying the old one, copies the values. Like e.g. Vector3 and Rect have.

avatar image bplunkett · Oct 03, 2013 at 06:48 PM 0
Share

Yes, something like that needs to happen in the long run. What's happening now is pretty inefficient. Right now I'm looking to see if there's a quick fix that can alleviate the hitch we're seeing and try to understand what's making $$anonymous$$arkDependencies take several seconds.

avatar image Jamora · Oct 03, 2013 at 06:49 PM 0
Share

I'd need to see some code to be able to tell you anything more.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kurtdog · Jul 29, 2017 at 10:42 PM

I'm having the same issue, huge gc.markdependcies spike in the CPU other section. For me it's when I disable a gameobject. I've optimized all the scripts on the object for GC performance (I think). Still getting the issue and can't tell what's causing it!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Intermittent slow downs in Unity - unrelated to garbage collector 1 Answer

Distribute terrain in zones 3 Answers

Invisible method costs? 0 Answers

ManagedHeap.ReservedUnusedSize 0 Answers

Multiple Cars not working 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