Re: Is FLTK performing automatic memory de-allocation of dynamically created objects?
Manolo
Sep 26, 2022
Hi Pierre,
One key information is that the destructor of an Fl_Group also deletes all the group's children :
see https://www.fltk.org/doc-1.3/classFl__Group.html#a9a71aac1ca586825ff0c790f8f99f9cf
Now, because FLTK widgets are placed in Fl_Window's and Fl_Window's are Fl_Group's,
when a window is deleted, all the widgets it contains are deleted too.
Another key information is that when you click on the close button of a window,
the window's default close operation occurs which is to call Fl_Window::hide(). This operation does not delete the window (nor its children). The benefit of that
is that you can call Fl_Window::show() later and the window and its children will
reappear. If you need to completely delete a window when its close button is clicked,
you have to change the window's callback, with Fl_Window::callback(), and assign it
a new callback function that does delete the window. At that point, all widgets contained
in the window will get deleted too.
Here is the relevant code to change the window's callback :
Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.