Question

I use C# (with XNA 4 and MonoGame). I load assets (textures, audio) using the Load() method of the Content Manager. When these assets are no longer needed, how can I properly Unload() them from memory?

I assume that once all references to the loaded assets are overwritten (or set to null) the assets are automatically removed by the Garbage collector. Is this correct or are the assets still locked due to the fact that they were loaded through the ContentManager?

Is it necessary to call 'ContentManager.Unload()' to release the assets of a particular CM?

Was it helpful?

Solution

Yes, if you want the assets in a content manager to be completely unloaded from memory, it's necessary to call Unload(). In addition to clearing out the content manager's internal cache (which holds references to everything you've loaded), it will call Dispose() on any resource which implements IDisposable.

Note that the reason that a ContentManager maintains an internal cache of resources is because loading the same resource twice doesn't actually load the same resource twice: the second time, it will simply hand you the cached object reference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top