FLTK logo

Re: [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: Re: Is FLTK performing automatic memory de-allocation of dynamically created objects? Pierre Rouleau Sep 26, 2022  
  contractor-> constructor in my previous question.
So: if the constructor does not call the `end()` member function, does this mean that the 'automatic' registration of widgets continue to operate inside calls to other member function of that class?



On Monday, September 26, 2022 at 9:31:04 AM UTC-4 Pierre Rouleau wrote:
On Monday, September 26, 2022 at 9:06:44 AM UTC-4 Albrecht Schlosser wrote:
On 9/26/22 14:08 Pierre Rouleau wrote:
On Monday, September 26, 2022 at 4:14:25 AM UTC-4 Manolo wrote:
Hi Pierre,

Hi Manolo, thanks for the answer.
 
One key information is that the destructor of an Fl_Group also deletes all the group's children :

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.


Ok, but if you have code that creates a pointer to a FL_button with new, like the following, don't you have to register that FL_Button somewhere so that it is know as a member?  Is the new operator overridden by FLTK?

        Fl_Button *fluidButton = new Fl_Button(25, 80, 70, 50, "button2");

No, the new operator is not overridden by FLTK, and yes, you need to register the button as a child of its parent group. But this is usually done automatically.

Every FLTK container widget (derived from Fl_Group) calls `begin()` in its constructor. This registers it as the "current group". If you create a new widget like in your code above, the constructor of that widget "registers" it as a child of the "current group" by calling something like `Fl_Group::current()->add(this);` i.e. the new widget adds itself to the "current group" as a child widget. This is necessary to handle events and draw the children of the container anyway.

A very simple example is test/hello.cxx which creates a window and a button that is implicitly added to the window. If you look at the code you will also see `window->end();` before the window is shown to disable further automatic adding of widgets to this Fl_Window (Fl_Group).

Of course you can also disable this automatism and add/remove widgets to Fl_Group widgets explicitly, but this is another story.

Ahhhh.  That make sense.  Thank you!! 
One more question: if the contractor does not call the end member function, does this mean that the 'automatic' registration of widgets continue to operate inside calls to other member function of that class?
 

--
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/1768e7db-6807-4227-ac71-0f8e4dfe30een%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'.