Force destroy Widget

Eirik Byrkjeflot Anonsen eirik at opera.com
Wed Dec 2 05:23:26 PST 2009


"LALLIER Cedric (EXT TEAMLOG)" <ext.teamlog.cedric.lallier at sncf.fr>
writes:

>    Hi,
>
>
>    I don't understand why the old widget is not destroyed. How can I force
>    the destruction?
>
>
>    /* Create widget */
>
>    wid_form = XtVaCreateManagedWidget("test_form", xmFormWidgetClass,
>    Root_wid, NULL);
>
>    printf("create wid_form : %p\n", wid_form);
>
>
>    /* Destroy widget */
>
>    XtDestroyWidget(wid_form);
>
>    printf("destroy wid_form : %p\n", wid_form);
>
>
>    /* Re create widget */
>
>    wid_form_element_rame = XtVaCreateManagedWidget("test_form",
>    xmFormWidgetClass, Root_wid, NULL);
>
>    printf("recreate wid_form : %p\n", wid_form);
>
>
>    /* Call widget */
>
>    wid_form = XtNameToWidget(Root_wid, "test_form");
>
>    printf("call wid_form : %p\n", wid_form);
>
>
>
>    Result :
>
>
>
>    create wid_form : 0x8a6be28
>
>    destroy wid_form : (nill)
>
>    recreate wid_form : 0x8a61ec8
>
>    call wid_form : 0x8a6be28  ß Why this is the old widget ????


You could try this code:

void * p = malloc(100);
printf("p: %p\n", p);
free(p);
p = malloc(100);
printf("p: %p\n", p);
free(p);


I think you will usually find that the two lines print the same address.
Would you still wonder why the first "free(p)" did not destroy the
pointer?

I suspect what you do in your code is largely equivalent to this
example: after freeing a block of memory you immediately allocate
another block of the same size.  Many memory allocators (particularly
those based on doug lea's malloc) will give you back the block you just
freed.

eirik



More information about the xorg mailing list