My game is creating memory even when I'm doing nothing

My game is doing creating memory for an unknown reason. If you wanna test it to observe why, here’s a link:

Perhaps it is the cloud objects being deleted and created? But even if i stand an a room without clouds in the game, memory is STILL being made without end, and it’s really really bothering me.

Perhaps the method UnloadContent is significant? I never used it because I don’t know how or what it’s for. If i use it properly, will this fix the problem? I don’t know what’s going on here. I don’t know why memory is constantly being created. I don’t know of any objects in the background being created.

you can use the performance profiler tools built in Visual studio to find out what is generating garbage / new objects constantly

i got this

i don’t know what the best options are

… If you wanna knowsomething about memory you check… The memory usage profiler? :smile:

1 Like

I just did more research and someone said it even leaks memory when you create a new blank project. Something to do with the Garbage collector?

It would help if you were a bit more specific about “someone said”. There is another thread here about garbage being generated in the SDL version of Mouse.GetState. I’m guessing that’s what you have seen?

I downloaded your game and ran it in the VS2015 memory profiler. There is no unbounded memory leak. It looks like normal behaviour for a regular .NET application. Most allocations are from the content load at the start.

If you highlight the allocations, you can see where those small allocations are happening.

In the small example above, you are

  • creating a new Random instance.
  • string operations, such as ToUpper() always allocate memory.
  • using Linq which is a well-known generator of lots of garbage.

Memory allocations inside namespaces such as System.Windows.Forms we have no control over.