Unloading Content

Hey guys, i was asked by my boss to check if i could unload textures from memory, since our application is going to running for a long time, and we need to make sure we have enough space for everything.

So i’m loading textures with the usual Content.Load and some with Texture2D.FromStream.


Textures loaded with Fromstream are independent from a content manager right? Can I just Dispose them?

Textures loaded with content.load can be disposed? without unloading all the content in the manager?
Can I achieve this by creating an extension that offers a method to remove a texture, where i look up the texture in the contentmanager dictionary, remove it and dispose it?

If i achieve this, will disposing also remove my texture in the graphics card memory (if i’m not mistaken textures “live” in the gcard memory to render it)?

Thanks, Roger.

You should manually dispose textures that were created without a content manager. Textures created using a content manager should not be disposed. Instead, the content manager should be unloaded (ContentManager.Unload). This means that textures for example different levels should have seperate content managers (and one more content manager for the common stuff).

1 Like

@Nezz Hm, that is not enough, maybe ill have to extend the content manager a bit.

but well is good to know this information, if I end up extending the CM ill post again about that here.


Here is my ContentTracker project, which extends ContentManager. It’s not as trivial to do as it might seem with the need to handle content items that internally load other IDisposable items (eg Model loads Texture etc). Although the project is very old you could probably take it as a start and strip out anything you don’t need.

The absolute science of memory manage re explained to the novice:


Calling dispose.

Threading allocates
threading.tasks manages
dispose garbage collect.

It is the belief of the lamen that the highest memory management is just calling dispose.

the highest memory mamagement is managing from the beginning to the end.