Search code examples
c++visual-studiomemory-leakssdlsdl-2

How do I track Unresolved allocations?


I've been working on and off on a game of mine for the last 2 years. I am developing it using SDL2.0 in Visual Studio. Since the first months of working on it I had realized that it had some memory leaks and I have finally decided to deal with them. I don't know why it is happening since I have checked multiple times that I am deallocating any memory that I am allocating. Either with new/delete or with SDL's functions.

The first thing I did was to check the memory profiler and I was indeed right. The next thing I did was to open the heap profiler and I can see that the allocations and deallocations of objects on the heap are all working as expected. The only thing that seems to be increasing steadily over time is the Unresolved allocations block. I am clicking on it but I can't really find any useful information about the source of these allocations. Is there a way I can trace their source?

The project is kinda big and I don't know what part of the code I should include for this. For anyone who wants to take a look at the code it is at https://github.com/PanosPetras/The_Great_War. I am suspecting that maybe some of the drawables are at fault but I don't have any evidence to support it (Probably the Button and the Label).


Solution

  • The way to solve issues of this kind is to introduce your own memory allocator (overload new) and have it store extra information in each memory block, for example the __FILE__ and __LINE__ of the code that invoked new.

    I would guess that there must be some ready-made library out there that will do that for you.

    Keep in mind, however, that in the gaming industry people generally try to avoid using new.