GC sequence and asset offloading in Unity3D

Sometimes we need to free up useless resources manually in game development. But I'm not sure what is best between

System.GC.Collect(); Resources.UnloadUnusedAssets(); 

and

 Resources.UnloadUnusedAssets(); System.GC.Collect(); 

AFAIK, both of them are asynchronous operations, and there can be no difference.

So my question is ...

  • Is there any difference?
  • If so, which is better?
+6
source share
1 answer

There is no difference between the two species.

System.GC.Collect() tells the .Net collector to collect objects that are mono-managed in a managed heap, and Resources.UnloadUnusedAssets - assets (textures, sounds, and other media) that are placed in the native heap. The two methods do completely different things, so there is no other that will be executed first. (As you said, they are both asynchronous, and you simply set a flag to suggest to the system that this may be the right time to collect.)

In fact, it’s not so often to call the GC to assemble yourself, except that you have a good reason. GC systems will run at the right time, most of which require forced garbage collection, not as necessary as you think.

If you are interested in learning about Unity memory, you can refer to this blog , which can tell you in detail.

+9
source

Source: https://habr.com/ru/post/948987/


All Articles