Hi, I have an app which works fine. But when I use valgrind on it to look for memory leaks it gives many such leaks. To reproduce the problem, I tried using valgrind on the minimal.cpp that was provided within the samples directory. And there too valgrind reports many memory leaks. Is memory leak an inherent part of wxWidgets? Or the things that valgrind reports as memory leaks are not relevant in this case. Some of the sample output from valgrind is given below. The problem is that I have a large program/project that reports a large amount of memory leaks even though I have made sure there are no such leaks from my end. For example, I have two parts of the program. First is a console app which is the main logic of the program and consists of several classes. When I use valgrind on that console app separately it reports no memory leaks. But then when I use wxWidgets as the main thread and do that console app work in a worker thread then valgrind reports many memory leaks. Is there a way to remove these memory leaks at least that are coming due to wxWidgets? In my program I have a list and it has custom elements. Also I have a button which says clear and when the user clicks on that button the old data from the list is cleared using DestroyChildren() and then new data is added to the list. Here the problem as seen in the system monitor is that every time I clear the data by pressing the button, the app's memory usage is increased by around 5MB even though the new data that is being filled in the list is exactly the same as the old one. So it should not increase the memory usage by so much. I am using Ubuntu 18.04.
==11588== 36,832 bytes in 1 blocks are still reachable in loss record 8,638 of 8,643
==11588== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11588== by 0xB869D7C: ??? (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.15.0)
==11588== by 0xB869DC5: ??? (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.15.0)
==11588== by 0xB8B91E8: ??? (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.15.0)
==11588== by 0xB86AABA: FT_Load_Glyph (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.15.0)
==11588== by 0x6448EE5: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11510.0)
==11588== by 0x6449B51: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11510.0)
==11588== by 0x63F47D3: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11510.0)
==11588== by 0x63F49F4: cairo_scaled_font_glyph_extents (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11510.0)
==11588== by 0x618675F: ??? (in /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0.4000.14)
==11588== by 0x6C78EA3: ??? (in /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0.4000.14)
==11588== by 0xCCC98D0: ??? (in /usr/lib/x86_64-linux-gnu/libharfbuzz.so.0.10702.0)
--------------------------------------------------------------------------------------------------------------------------
==11588== 96 bytes in 1 blocks are still reachable in loss record 7,262 of 8,643
==11588== at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11588== by 0x7375C30: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5600.4)
==11588== by 0x70FD789: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x7103A91: g_type_register_static (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x7103D64: g_type_register_static_simple (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x57E9BB9: gtk_orientable_get_type (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x56A2970: gtk_box_get_type (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x56A2BFE: gtk_box_new (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x24E531: wxTopLevelWindowGTK::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588== by 0x22E95E: wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (frame.h:31)
==11588== by 0x22C700: MyFrame::MyFrame(wxString const&) (minimal.cpp:142)
==11588== by 0x22C606: MyApp::OnInit() (minimal.cpp:124)
==11588==
==11588== 96 bytes in 1 blocks are still reachable in loss record 7,263 of 8,643
==11588== at 0x7104AB4: g_type_create_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EB782: g_param_spec_internal (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EF70A: g_param_spec_enum (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x57E9B45: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x70FDBB0: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70FFA79: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x7101367: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E7727: g_object_new_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E78E8: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x24E531: wxTopLevelWindowGTK::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588== by 0x22E95E: wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (frame.h:31)
==11588== by 0x22C700: MyFrame::MyFrame(wxString const&) (minimal.cpp:142)
==11588==
==11588== 96 bytes in 1 blocks are still reachable in loss record 7,264 of 8,643
==11588== at 0x7104AB4: g_type_create_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EB782: g_param_spec_internal (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EF379: g_param_spec_int (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x56A1F29: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x7101438: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E7727: g_object_new_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E78E8: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x24E531: wxTopLevelWindowGTK::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588== by 0x22E95E: wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (frame.h:31)
==11588== by 0x22C700: MyFrame::MyFrame(wxString const&) (minimal.cpp:142)
==11588== by 0x22C606: MyApp::OnInit() (minimal.cpp:124)
==11588== by 0x4910B1: wxEntry(int&, wchar_t**) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588==
==11588== 96 bytes in 1 blocks are still reachable in loss record 7,265 of 8,643
==11588== at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11588== by 0x7375C30: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5600.4)
==11588== by 0x70FD789: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x7103A91: g_type_register_static (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E14E7: g_enum_register_static (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x58F3F5A: gtk_baseline_position_get_type (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x56A1F7F: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x7101438: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E7727: g_object_new_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E78E8: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x24E531: wxTopLevelWindowGTK::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588== by 0x22E95E: wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (frame.h:31)
==11588==
==11588== 96 bytes in 1 blocks are still reachable in loss record 7,266 of 8,643
==11588== at 0x7104AB4: g_type_create_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EB782: g_param_spec_internal (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EF70A: g_param_spec_enum (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x56A1FCC: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x7101438: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E7727: g_object_new_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E78E8: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x24E531: wxTopLevelWindowGTK::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588== by 0x22E95E: wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (frame.h:31)
==11588== by 0x22C700: MyFrame::MyFrame(wxString const&) (minimal.cpp:142)
==11588== by 0x22C606: MyApp::OnInit() (minimal.cpp:124)
==11588== by 0x4910B1: wxEntry(int&, wchar_t**) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588==
==11588== 96 bytes in 1 blocks are still reachable in loss record 7,267 of 8,643
==11588== at 0x7104AB4: g_type_create_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EB782: g_param_spec_internal (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EF3F9: g_param_spec_uint (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x56A20CB: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x7101438: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E7727: g_object_new_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E78E8: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x24E531: wxTopLevelWindowGTK::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588== by 0x22E95E: wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (frame.h:31)
==11588== by 0x22C700: MyFrame::MyFrame(wxString const&) (minimal.cpp:142)
==11588== by 0x22C606: MyApp::OnInit() (minimal.cpp:124)
==11588== by 0x4910B1: wxEntry(int&, wchar_t**) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588==
==11588== 96 bytes in 1 blocks are still reachable in loss record 7,268 of 8,643
==11588== at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11588== by 0x7375C30: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5600.4)
==11588== by 0x70FD789: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x7103A91: g_type_register_static (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E14E7: g_enum_register_static (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x58F431A: gtk_pack_type_get_type (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x56A20D7: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x7101438: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E7727: g_object_new_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E78E8: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x24E531: wxTopLevelWindowGTK::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588== by 0x22E95E: wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (frame.h:31)
==11588==
==11588== 96 bytes in 1 blocks are still reachable in loss record 7,269 of 8,643
==11588== at 0x7104AB4: g_type_create_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EB782: g_param_spec_internal (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EF70A: g_param_spec_enum (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x56A2121: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x7101438: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E7727: g_object_new_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E78E8: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x24E531: wxTopLevelWindowGTK::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588== by 0x22E95E: wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (frame.h:31)
==11588== by 0x22C700: MyFrame::MyFrame(wxString const&) (minimal.cpp:142)
==11588== by 0x22C606: MyApp::OnInit() (minimal.cpp:124)
==11588== by 0x4910B1: wxEntry(int&, wchar_t**) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588==
==11588== 96 bytes in 1 blocks are still reachable in loss record 7,270 of 8,643
==11588== at 0x7104AB4: g_type_create_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EB782: g_param_spec_internal (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70EF379: g_param_spec_int (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x56A2178: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2200.30)
==11588== by 0x7101438: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E7727: g_object_new_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x70E78E8: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4)
==11588== by 0x24E531: wxTopLevelWindowGTK::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588== by 0x22E95E: wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) (frame.h:31)
==11588== by 0x22C700: MyFrame::MyFrame(wxString const&) (minimal.cpp:142)
==11588== by 0x22C606: MyApp::OnInit() (minimal.cpp:124)
==11588== by 0x4910B1: wxEntry(int&, wchar_t**) (in /homedir/username/Documents/wxWidgets-3.1.5/samples/minimal/program)
==11588==
---------------------------------------------------------------------------------------------------------------------------------------------------------------
==11588== LEAK SUMMARY:
==11588== definitely lost: 8,024 bytes in 29 blocks
==11588== indirectly lost: 13,562 bytes in 414 blocks
==11588== possibly lost: 4,990 bytes in 52 blocks
==11588== still reachable: 2,292,302 bytes in 26,303 blocks
==11588== of which reachable via heuristic:
==11588== length64 : 6,680 bytes in 107 blocks
==11588== newarray : 2,128 bytes in 53 blocks
==11588== suppressed: 0 bytes in 0 blocks
==11588==
==11588== ERROR SUMMARY: 560 errors from 56 contexts (suppressed: 0 from 0)