[comp.windows.x] Xt and the Destroy method

zoo@armadillo.spa.umn.edu (david d [zoo] zuhn) (08/08/90)

I have been trying to get Xt to call the Destroy method for my widget,
without any success.  

The Destroy field in the refMenuClassRec is filled with the pointer to
the function.  In a simple example, I create a top_level widget, and
then one instance of my widget.  If I call XtDestroyWidget on the top
level widget, and call this during my exit routine, everything dies
nicely, except that the Destroy method is NOT called.  If I try
XtDestroyWidget directly on the widget, and not going through the top
level, the same thing happens.

Can anyone say that their Destroy methods are being called?   Can you
send me sample code?   

Relevants:  X11R4, pl14.  SunOS 4.1 & Dynix 3.0.17

swick@ATHENA.MIT.EDU (Ralph Swick) (08/08/90)

    If I call XtDestroyWidget on the top
    level widget, and call this during my exit routine, everything dies
    nicely, except that the Destroy method is NOT called.  If I try
    XtDestroyWidget directly on the widget, and not going through the top
    level, the same thing happens.

Don't forget that widget destruction happens in 2 phases.  If you
call XtDestroyWidget while XtDispatchEvent is active the cleanup
is deferred until the very last stage of XtDispatchEvent, just before
it returns.  If the application exits before returning to XtDispatchEvent
then the destroy methods will never be invoked.

This is done so that applications can write callback procedures
and action procedures without having to worry about data structures
disappearing from underneath them.

zoo@APS1.SPA.UMN.EDU ("david d [zoo] zuhn") (08/08/90)

Ralph Swick writes:
 >     If I call XtDestroyWidget on the top
 >     level widget, and call this during my exit routine, everything dies
 >     nicely, except that the Destroy method is NOT called.  If I try
 >     XtDestroyWidget directly on the widget, and not going through the top
 >     level, the same thing happens.
 > 
 > Don't forget that widget destruction happens in 2 phases.  If you
 > call XtDestroyWidget while XtDispatchEvent is active the cleanup
 > is deferred until the very last stage of XtDispatchEvent, just before
 > it returns.  If the application exits before returning to XtDispatchEvent
 > then the destroy methods will never be invoked.
 > 
 > This is done so that applications can write callback procedures
 > and action procedures without having to worry about data structures
 > disappearing from underneath them.

This is indeed the case.  My exit() call was getting in the way here.
When I just called XtDestroyWidget on the widget, but did not exit the
application, my Destroy method was called.  

This is what happens when test programs are too simple sometimes.  

Thanks Ralph.


Zoo