|
|
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.
Rob
--
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/c94180ca-92d2-4ff4-b439-54b9aedf6176n%40googlegroups.com.
[ Direct Link to Message ] | |
|
| |