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.
questions:
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)?
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).
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.