Re: Re: Newbie: question about destruction of FLTK ojbects
imm
14:06 Sep 27
On Sun, 27 Sept 2026 at 14:42, Daniel G. wrote:
>
>
> > 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.
Hi Daniel,
Well... it does kinda depend, really...
(Here's comes a warstory I've posted before... sorry...)
Years ago, I was working on a complex app. A new start was assigned to
our team, and as part of his on-boarding he was tasked with cleaning
up a load of papercuts and issues in the code base; a good way to get
familiar with it all.
As he was going along, being fresh out of school, he added explicit
destructors for all the "lifetime" objects (which we had deliberately
NOT destroyed explicitly.)
The upshot was that the app went from terminating "instantly" on exit,
to taking 2 or 3 minutes.
We got A LOT of user complaints.
He was made to go back and remove 'em all...
Note that we knew (valgrind et all) that we were not leaking memory,
or indeed any other resources.
>
> > 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.
Only if the object holds some resource that can't or won't be freed by
the OS on process termination, e.g. a file handle or similar, say, or
if you depend on the destructor being called to perform some other
action(s) on object termination.
That does not apply to any stock FLTK widget - the OS will always
unmap the memory resources, and FLTK widgets don't really hold
anything else that "must" be done when the app terminates.
So in the OPs case, I don't think this will be an issue.
If you derive your own widget, and it holds any non-memory resource,
then you DO need to ensure it is released, but memory only objects,
it's fine, always.
I do not know any OS where this does not work, even the hack toy OS's
that I've written do this correctly!
--
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/CAGFM6dYFwft6zgi4_Bgin7pB%3DJf0YydE3shGGWS78Ft7yUVSpQ%40mail.gmail.com.
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'.