FLTK logo

[fltk.general] Re: Is FLTK performing automatic memory de-allocation of dynamically created objects?

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

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 :

static void delete_when_closed(Fl_Widget *win, void *data) {
  Fl::delete_widget(win);
}

// elsewhere in the code where the window is created
  Fl_Window *win = ……
  win->callback(delete_when_closed, NULL); // change the window's callback


--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/f2a0d45e-6867-4295-9618-14b699f3f03bn%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.