# Memory accumulation in monogame. ‘Dispose’ and ‘Unload’ aren’t working

I'm having a huge problem with memory accumulation in all my games. This happened after switching from monogame 3.4 to 3.5 so I switched back. Then recently I went to 3.6(latest release) and started having the same problem again. I would switch back again but I need 3.6 rather than 3.4 for certain reasons.

I've tried both .Dispose() and .Unload() for the content but it seems to only release a small portion of what was previously loaded.

Here is the code

public void UnloadContent()
{
if (overworldContent != null)
{
}
}


I've also done

public void UnloadContent()
{
if (overworldContent != null)
{
overworldContent.Dispose();
}
}


This is a picture of the memory usage from just going in and out of an area just a few times over the course of several minutes. A player could easily have multiple gigabytes taken up from playing for even just one hour if it goes from 86MB to 235MB in just 2 minutes

I seriously need help.

• I think UnloadContent only gets called at the end of the game if this is the method from the main class. You need to dispose of content elsewhere too if you don't want it to increase constantly. – Bálint Nov 21 '17 at 19:20
• Unload is in fact being called and every area in the game has it's own content manager that I'm utilizing. – Brent Nov 21 '17 at 20:13
• This is quite a tricky question to answer. You'll probably need to do some reading on what causes memory issues in C# and consider using a memory profiler – craftworkgames Nov 22 '17 at 0:53
• is the only change moving to another version, or are there related code changes? for debugging, you can try GC.Collect () after you unload/dispose to see if the memory clears. if not, then the objects likely still have references somewhere. – Joel Nov 22 '17 at 8:43

        if (overworldContent != null)