On Saturday, December 25, 2021 at 6:05:41 AM UTC-8 Albrecht Schlosser wrote:
> Foo::~Foo()
> {
> m_Display->buffer( NULL );
> delete m_Buffer;
> }
>
> Is this the proper way to clean up in this situation?
Yes, I think this is the correct solution. Think about the way you
create the two objects (Fl_Text_Display and Fl_Text_Buffer) and then
connect them. Destroying them correctly would be the opposite order:
break the connection, then delete the two objects. Since Fl_Text_Display
and Fl_Text_Buffer are independent of each other the order wouldn't matter.
However, if you deleted the Fl_Text_Display object first it should work
as well because it would break the connection in its destructor. The
only thing you must not do is to delete the Fl_Text_Buffer first while
it is still asscociated with the Fl_Text_Display.
> I might be able to make the Fl_Text_Buffer a direct member variable
> (instead of a pointer allocated with new), but I can still imagine
> situations where this would arise.
>
> Am I missing something?
Not really AFAICT, but remember the fact that one Fl_Text_Buffer can be
associated with more than one Fl_Text_Display or Fl_Text_Editor at the
same time or of course one after the other with the same
Fl_Text_Display. There's no automatism to destroy them together because
there's no "ownership". The Fl_Text_Buffer does not even "know" that it
is associated with one or more Fl_Text_Display's.
Thanks for the confirmation -- that is pretty much the understanding I had come to.
FLTK has no guarantees about a particular buffer being paired to a particular Display -- but in my application, I can have such guarantees.
Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.