I recently realized Texture2D implements IDisposable, and now (while trying to track down a memory leak) wonder about where and when I should dipose this.
My current architecture is that I have a SpriteComponent instance which encapsulates and hides the Texture2D. Internally, when I switch screens (eg. MainMenuScreen => WorldMapScreen), I call Dispose on the current screen, which calls dispose on the entities, which calls dispose on the textures.
But this results in some wacked-out behaviour, like textures apprearing super zoomed in momentarily, or appearing black, or appearing as garbage image data.
So my question is really, when should I call Dispose on Texture2Ds?
(FYI, I also can switch to a screen, and then later switch back to it, which currently causes me to reload the sprites, and by proxy, the textures.)
Disposethem at all ;) You have to unload the wholeContentManagerso it will also stop caching the disposed instances. \$\endgroup\$