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
0
Question by MrEastwood · Sep 18, 2016 at 02:55 PM · memoryprofilinggarbage-collectionallocation

Total GC increases without GC allocated

I'm memory profiling my game and i'm trying to explain something. There is a periodic increase in memory that seems to come from something other than my scripts. In the hierarchy i can usually see which script is responsible for an increase in allocated memory, but in this case it looks like it just doesn't register. The GC allocated graph seems to confirm that this does not originate from my scripts, so what are other things that could be causing it? Does Total GC allocated include stuff from the engine? If so how do i find out what it is?

One caveat is that i'm running some background threads but as far as i can tell i disabled them all for this profiling round. I verified that if a thread other than the main tread allocates memory it will show up in Total GC but not in GC allocated. That being said, is there something else that will show up like this? Memory profiler graph

total-gc-vs-allocated.png (67.4 kB)
Comment
Add comment · Show 5
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 MrEastwood · Sep 30, 2016 at 06:33 AM 0
Share

It seems the mystery allocations are done in between frames!

I made a script that uses System.GC.GetTotal$$anonymous$$emory(false) to measure the total amount of allocated memory in Update and used Script Execution Order to make sure this script is the very first script to have its update method called. I then use a coroutine with WaitForEndOfFrame() to measure it again. According to the documentation this Waits until the end of the frame after all cameras and GUI is rendered, just before displaying the frame on screen. Between update and end of frame i see expected amounts of memory being allocated. The weird ones seem to happen between end of frame and the next first update of the next frame. According to the execution order not much happens in between. OnApplicationPause (but i'm not pausing), OnEnable and OnDisable, physics updates and input updates. Granted, physics could be the culprit but at least FixedUpdate should register normally in the profiler. I'll investigate physics further, but i'm not using a lot of physics save for a couple of raycasts.

avatar image Bunny83 · Sep 30, 2016 at 08:19 AM 0
Share

Have you created a deep profile? Also what "stuff" do you use? Do you use physics / uGUI / Nav$$anonymous$$esh / Terrain / ...? When exactly does this jump happen? Just after some idle time or do you provide any kind of input? Even changing the camera direction counts as input.

You said "periodic increase". Does that mean it's constantly increasing and raising the average memory usage over time? How long did you run your test? ever run out of memoty?

avatar image MrEastwood Bunny83 · Sep 30, 2016 at 03:29 PM 0
Share

Yep, the screenshot is from a session with deep profiling enabled. The hierarchy view shows the purple allocations, a couple of kb, but nothing that amounts to 20mb. I use no uGUI, Nav$$anonymous$$esh or Terrain. Physics is only a couple of raycasts. The jumps seem a bit unpredictable but keep happening every $$anonymous$$ute or two. The camera moves continuously and is rotated by the player (looking around). I don't run out of memory, the allocations are reclaimed later when garbage collection occurs. The problem is that i get a hiccup both at the time of the allocation and at the garbage collection that cleans it up. I do generate some meshes procedurally so the next thing i'm going to check is whether or not assigning a (low poly) physics mesh stays off the profiling radar.

avatar image Bunny83 MrEastwood · Sep 30, 2016 at 05:49 PM 0
Share

How often do you generate those meshes? Do you reuse the mesh instances or do you create new ones? If you create new ones, do you Destroy your old? $$anonymous$$eep in $$anonymous$$d that the internal meshcollider generation is quite heavy (convex or normal?).

Show more comments

1 Reply

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

Answer by MrEastwood · Oct 03, 2016 at 02:11 PM

Well i finally found what was causing the allocations. Long story short: if the console says "The profiler has run out of samples for this frame. This frame will be skipped. Increase the sample limit using Profiler.maxNumberOfSamplesPerFrame", don't ignore it! The frame that was responsible for the allocations was skipped, causing the measurements for GC allocated to be dropped. But the allocations were visible in the next frame that was not skipped through total GC.

Long story long: we were running some background threads to do some heavy lifting. As i said before, it a background thread allocates memory the profiler won't show it in GC allocated. So we made an option to run everything on the main thread. Of course you get terrible performance but the goal was to figure out which method was responsible for the memory. So now you have some updates that take a very long time. I don't know the specifics of the profiler but my hunch is that it just checks what the main thread is doing every couple of nanoseconds and then attributes any time spent that way. Of course if a frame takes an excessive amount of time then you get the error quoted above, the profiler will run out of samples. The thing i missed every time is that it actually literally tells me that it skipped the frame. So the answer was to to exactly as the error suggested, i increased the maximum amount of samples.

And of course it makes sense that the frame that takes so much time that the profiler runs out of samples is the frame that allocates a huge amount of memory.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Memory profiler freezes editor/crashes build on device 0 Answers

Don't allocate memory in Update loops on iOS. - How strictly should this be followed? 2 Answers

How important is it to wrap temp variables/objects in a "using" block? 4 Answers

calling www to get audio.clip multiple times causes memory problems 1 Answer

Setting Active Profiler to WindowsPlayer does nothing 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