I’ve been digging through the ContentManager code, and it never releases unused content. I don’t see any reference counting or anything, and correct me if I’m wrong but I also don’t see anything like Unload(…)
I’ve been trying to plug this memory leak by using multiple ContentManagers, and it works awesome on every platform I’ve tried except DesktopGL. While I put together a proper bug report, is there a better way of releasing unused content?
You mean that content is not unloaded implicitly? That’s by design. You can only release all content loaded by a content manager at once by calling Unload (that’s called when you call Dispose on the ContentManager too). For managed memory, the content manager keeps a reference to everything it loaded, so the only way to have your content garbage collected is to unload the content manager.
You mean like unloading specific content? That’s not supported through the API. I’m not sure why they chose to do it like that in XNA.
I don’t understand what difference between DesktopGL and Windows DX you’re talking about. ContentManager does not (directly) have any platform specific code.
On DesktopGL, when a spritefont or texture is released by unloading one ContentManager, loading it in a second ContentManager can act squirrelly. For example if I load and unload ArialBlack.spritefont several times, all of a sudden my text might be drawn with Background.jpg instead. I’ve tested it in several different projects but having a hard time determining why/when this behavior is triggered, which is why I’m having a hard time writing a bug
I only see it on MonoGame.DesktopGL, MonoGame.Android and MonoGame.iOS are fine, which leads me to believe it might some sort of SDL/implementation bug. Which is why the easiest fix for me would be to abandon ship on desktopgl and switch to MonoGame.WindowsDX ¯_(ツ)_/¯