0

I have installed gtkmm trough vcpkg. (gtkmm 3.22.2-2 and gtk 3.22.19-3) If I try to compile simple example provided in gnome tutorials. It shows memory leak at the end of the execution. Some people said its not leak, gnome intentionally leaves releasing the allocated resources to operationg system as an optimization. And a similar problem reported in Debian using valgrind. Well, I cannot distinguish real leaks with gnome optimizaton ... I want to learn how can I properly exit from a gnome app. Here is my way of checking leaks with CRT memdebug utilities.

#include <gtkmm.h>

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

#ifdef _DEBUG
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#else
#define DBG_NEW new
#endif

int main(int argc, char* argv[])
{
  _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  {
    auto app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base");

    Gtk::Window window;
    window.set_default_size(200, 200);

    app->run(window);
  }

  return 0;
}
Cihan
  • 175
  • 1
  • 3
  • 14

1 Answers1

0

There's a suppression file for Valgrind that covers any false-positive leaks inside GTK. There are similar files for GLib and other libraries used by GTKMM. You'll have to adapt these somehow to the memory debugging tool you're using.

Also make sure you have set the environment variable G_SLICE=always-malloc because otherwise the blocks used by GLib's internal allocator will be considered leaks.

ptomato
  • 56,175
  • 13
  • 112
  • 165