On 5/29/23 08:39 Lucas Sanner wrote:
> > OK, then you should see printf() output to stdout.
>
> Yes I do, but provided I call the Application destructor:
> ~Application()
> {
> delete myClass;
> }
Sure. I wanted to emphasize that you would see printf output on Linux
and other OS's whereas Windows (particularly Visual Studio builds) would
*suppress* the output even *if* you called the destructor.
> So it goes to show that memory dynamically allocated by a custom class
> has to be freed explicitly, if I understand correctly.
As Ian wrote... (see his reply).
The issue lies in the wording "memory dynamically allocated" and not in
"custom class" or not (as opposed to FLTK classes if that's what you
mean). If we define "dynamically allocated" as "allocated by operator
new" then such objects must be deleted explicitly, but as Ian explained
FLTK will do this for you for all children of container widgets if/when
their parent widgets are deleted. Your "Application" class is the main
window, i.e. the parent of all other widgets, and will therefore not be
deleted automatically, unless ...
Here comes the C++ automatism into play: if you allocate a widget on the
stack (as local variable) rather than with 'new' it will be deleted by
the C++ runtime as soon as the object goes out of scope. This is the
difference I mentioned in my first reply and has nothing to do
specifically with FLTK, it's a C++ property.