FLTK logo

Re: [fltk.general] Re: Newbie: question about destruction of FLTK ojbects

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

Re: Re: Newbie: question about destruction of FLTK ojbects "Daniel G." 13:42 Sep 27  
 
> Well... this is "mostly true", and probably if you were doing this on
a school course the tutor would expect you to delete any object you
new'd...

Because it is good practice to take care of the things you own :D If you yield ownership thats a different story.

> Secondly, any widget that has a lifetime until the app process
terminates, need not be explicitly deleted, since the OS will
automatically unmap all the app memory on process exit, which in
effect deletes all your widgets "for free".

But no CTor is called, which can lead to unwanted behaviour (exactly what OP observed). Also I would never fully trust the OS.

Back to OP as a newbie:

Learn about pointers, ownership and object lifetime, RAII etc.!
Ian MacArthur schrieb am Sonntag, 27. September 2026 um 14:47:57 UTC+2:
On Sun, 27 Sept 2026 at 12:36, Daniel G. <dani.g...@gmail.com> wrote:
>
> in C++ if you create objects with the keyword 'new' you need to delete them yourself with 'delete'.

Well... this is "mostly true", and probably if you were doing this on
a school course the tutor would expect you to delete any object you
new'd...

But in reality, there are some subtleties to this, and that are
pertinent to what FLTK is doing.

Firstly, note that any FLTK widget that is a child of a FLTK container
widget (usually a group or a window, though there are others) will be
cleaned up automatically by FLTK when the container is tidied up.

Secondly, any widget that has a lifetime until the app process
terminates, need not be explicitly deleted, since the OS will
automatically unmap all the app memory on process exit, which in
effect deletes all your widgets "for free". (This process is much
faster than explicitly walking the widget hierarchy and manually
deleting every widget, so is preferred in cases where it is
appropriate - but your school tutor will probably be unhappy about
it!)

This second case may well be what the OP is seeing, since the window
persists until the app exits, at a guess.

--
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 visit https://groups.google.com/d/msgid/fltkgeneral/d372ca87-7c14-4f17-9a98-99611e131d5an%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-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.