Handmade Hero»Forums»Code
Matt Hartley
23 posts
I like to program the things.
Memory leak?
I opened up task manager the other day and found that my game is leaking quite a lot of memory, about 100KB per second.
I only time I allocate memory is when the program starts up and when assets are loaded.
I used #define to also output to the console on allocation just to make sure and I'm using STB libraries so I did the same for those to make sure the allocations weren't coming from them. I can now see that once the assets are loaded no more allocations are done and yet the leaking still occurs.

Is there anything else that could be causing this? I'm all out of ideas.

Thanks
Jim R. Didriksen
63 posts
Memory leak?
Are you looking at what the game is using or what it has gotten allocated.

In windows 10 I can't even find what the game has gotten allocated in the task manager so it just shows what has been used which would look like a memory leak until you hit the allocated sum of your allocated memory.
Matt Hartley
23 posts
I like to program the things.
Memory leak?
I'm using Windows7, the task manager looks like this:

Bryan Taylor
55 posts
Memory leak?
There are a few columns regarding memory in Task Manager.

The default one shown is the Private Working Set -- this is the memory the process is using that cannot be shared. In other words, it's the memory you've actually accessed; for another process to get that memory the OS has to page out your memory.

If you're looking solely at allocations, use the Commit Size. That's the amount of memory you've allocated and committed. The size of your address space, basically. The OS has to ensure you can access that memory when needed, but not all of it is actually allocated to physical memory -- it will page fault in when you first access it.
Matt Hartley
23 posts
I like to program the things.
Memory leak?
Ah I didn't know there were more columns, the Commit Size column stays the same unless a new asset is loaded so it's not leaking.

I guess the Private Working Set would keep increasing as more entities get added to the world and their memory is accessed.

That's very helpful thank you.