On 22.08.2011 11:30, asif saeed wrote:

> The docs say that the groups automatically add whatever children get created
> after them - they automatically issue a begin or something like that -
> apparently each widget adds itself to the group in its constructor. I read
> that while reading about creating members on heap using new(). I also read
> that the groups automatically delete the children. Now if you create
> children on stack then they will first be released via stack pop and then
> the group will delete them - and here the group will delete something that
> will have already been deallocated through stack unwinding.

The order matters here. Of course you create the group first, and then
you add the children on the stack. This guarantees that the children
will be deleted first, and in FLTK 1.3 and later this will also remove
each child from its group. Eventually, when the group will be deleted,
all children that were created on the stack, have already removed them-
selves from the group. Only children allocated with new will still be
contained in the group and have to be released.

It is your responsibility not to add other (static) widgets to a group
and let the group delete them on destruction. In this case you must
remove these children from the group before deleting the group.

In FLTK 1.1 and probably also 2.0 there is a "kludge" that shall assure
that no double deletion takes place, but this has other drawbacks, i.e.
there is a potential to access memory of deleted objects (children).

Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to