[comp.windows.x.motif] the "text" of an XmText Widget

argv@turnpike.Eng.Sun.COM (Dan Heller) (08/12/90)

Perhaps someone from osf and can answer this:
When you set the text widget's "value", you don't need to keep
around it's memory any longer, do you?  I'm reasonably sure
it copies it into internal data space, but I can't find anywhere
in the source that does it.  I do see places where it's copied
into _temporary_ internal buffers but not into permanent space.

The example programs that set the text's value use allocated
space and they never free it, but:
    1) they never get the previous text and free it before assigning
	the new text -- does XmText do that automatically?
    2) I tried freeing the text immediately after setting the text's
	value and it works fine in many programs.  I haven't seen a
	problem.  Does this mean that my assumption is right that
	the XmText widget copies and manages its own text?

--
dan
----------------------------------------------------
O'Reilly && Associates   argv@sun.com / argv@ora.com
Opinions expressed reflect those of the author only.

carl@quad1.quad.com (Carl Priddy) (08/15/90)

From postnews Tue Aug 14 11:27:10 1990
In article <140523@sun.Eng.Sun.COM>, argv@turnpike.Eng.Sun.COM (Dan Heller) writes:
> Perhaps someone from osf and can answer this:
> When you set the text widget's "value", you don't need to keep
> around it's memory any longer, do you?

Dan,
No you do NOT need to keep it around any longer. I believe, although I am not
sure and have no hope of finding it documented anywhere, that all widgets that
have string resources make copies of those strings. I too have experienced no
problems after free'ing up the memory that contained them after I have set
the values in the widgets.
As to whether or not the widgets do the appropriate alloc and frees, one can
only hope.
I notice that you are from O'Reilly & Co. I am counting on you guys to provide
relief for the Motif documentation vacuum. Good luck.
carl.

mayer@hplabsz.HPL.HP.COM (Niels Mayer) (08/17/90)

In article <14342@gouda.quad.com> carl@quad1.quad.com (Carl Priddy) writes:
>No you do NOT need to keep it around any longer. I believe, although I am not
>sure and have no hope of finding it documented anywhere, that all widgets that
>have string resources make copies of those strings. I too have experienced no
>problems after free'ing up the memory that contained them after I have set
>the values in the widgets.

In theory, what you said is supposedly true.

But.... in Motif 1.0, if you set XmNargv on an applicationShellWidgetClass
instance to a recently malloc()'d argv and do XtFree(argv_copy) right after
doing XtAppCreateShell(), you get a guaranteed core dump. If you free after
doing XtRealizeWidget(), you don't....

>As to whether or not the widgets do the appropriate alloc and frees, one can
>only hope.

Leaks? What leaks?

-- Niels "canary in a coal mine" Mayer.