Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

UnloadUnusedAssets causes GC.MarkDependencies to spike

Discussion in 'Editor & General Support' started by TommiH, Aug 8, 2019.

  1. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    252
    We're loading out levels asynchronously in small chunks (using SECTR), and unloading the parts that get too far away. UnloadUnusedAssets is called when parts are unloaded in order to clear away orphaned assets. Unfortunately, this seems to cause massive spikes (up to 450ms), attributed by the profiler to GC.MarkDependencies (UnloadUnusedAssets is not in the call stack, but I know from experimentation that calling it is the trigger). This spike is smaller if there are fewer objects in the main scene (size of the small additive scenes seems to have little effect).

    My interpretation is that when UnloadUnusedAssets is called, it needs to check every possible reference in the main scene, and any reference in assets they reference, to see which assets are unused. This seems like a really inefficient method, but that's all I can think of. I'd appreciate any alternative theories, or advice in avoiding this issue. I could remove the call to UnloadUnusedAssets, but that would mean we'd have to manually manage the asset loading and unloading. Profiler - GC.MarkDependencies.PNG
     
unityunity