GTK3 memory usage / leaks

I’m finding that my app over time starts using more and more ram. I’m probably leaking references or something. I know that I’m not leaking bulk amounts of memory in my own code unrelated to GTK. And I’ve fixed a bunch of leaks already. So I suspect the problem is in how I’m using GTK.

One avenue is to turn on _CRTDBG_MAP_ALLOC, because I’m using Windows and Visual Studio 2015. I did actually get vcpkg to build v3.24.10 this afternoon. But I think it’s all using the glib malloc and free functions so I need to work out how to get some runtime stats on that. Maybe glib already has a way of dumping the entire heap?

Currently using the CRT debug heap I get stats like this:

27,740 kb c:\users\matthew\code\lgi\trunk\include\common\GArray.h:314
14,262 kb (null):0
13,284 kb C:\Users\matthew\Code\Lgi\trunk\src\common\Text\GXmlTree.cpp:1237
12,288 kb C:\Users\matthew\Code\Lgi\trunk\src\common\Text\GXmlTree.cpp:78
4,453 kb C:\Users\matthew\Code\Scribe\trunk\Code\Store3Imap\ScribeImap_Folder.cpp:599
2,190 kb C:\Users\matthew\Code\Scribe\trunk\Code\Store3Mail3\Mail3Store.cpp:451
2,176 kb C:\Users\matthew\Code\Lgi\trunk\src\common\Gdc2\Font\GFont.cpp:1281
2,086 kb C:\Users\matthew\Code\Lgi\trunk\src\common\Text\GString.cpp:374
2,077 kb C:\Users\matthew\Code\Scribe\trunk\Code\ScribeApp.cpp:8794
1,751 kb c:\users\matthew\code\lgi\trunk\include\common\LHashTable.h:411
1,090 kb C:\Users\matthew\Code\Lgi\trunk\src\common\Gdc2\Font\GFontSystem.cpp:104
1,033 kb c:\users\matthew\code\lgi\trunk\include\common\GArray.h:167

That NULL entry is all the GTK allocated memory I guess.

Another thing I’ll try later tonight is running the app on Mac and using the instrumentation app with Xcode. That seems to be able to dive into the heap at runtime without compile time steps. But if there are better ways, esp windows specific, I’m all ears.

No, it doesn’t.

You could look into using Valgrind on Linux, if your application can be built/used on there. Otherwise you will need a memory check tool to show you the call stack.

Visual Studio apparently has its own leak-detection features, though they involve linking a library into your application (CRT, the C Run-Time, which maps malloc() and free() to debug versions with allocation tracking) and using the debugger, rather than running an external tool like valgrind.

Where can I get support for the OSX port of GTK3? Is there somewhere more specific than here?