[comp.windows.x.motif] Freeing XmStrings????

sdk@RUDEDOG.SAIC.COM (Scott D. Kessler) (06/20/91)

I'm not clear on when an XmString should/shouldn't be freed.
For example: When filling a list that was previously empty
I create a string with XmStringCreate and then add it to the
list. Do I then need to free the created string or will this
free the string stored in the list?

Also, I'm having scrolled lists that randomly don't appear! That
is to say that one time the full list will appear with the scrollbar
and the next time it will appear only as a postage stamp size box
with no scroll bar or anything. Yet if I click in that little box
the items are still there because I can select the very first one.
Anyone seen anything like this before?  

On the same note i'm also experiencing random window growths. Out of the
blue a FormDialog will suddenly grow to twice it's size!!

Thanks for any help in advance!!

Scott
sdk@rudedog.saic.com

jr@dkwgate.uucp (J.R. Jesson) (06/21/91)

In article <9106192231.AA00290@rudedog.saic.com> sdk@RUDEDOG.SAIC.COM (Scott D. Kessler) writes:
>
>I'm not clear on when an XmString should/shouldn't be freed.
>For example: When filling a list that was previously empty
>I create a string with XmStringCreate and then add it to the
>list. Do I then need to free the created string or will this
>free the string stored in the list?
>

The answer to freeing XmStrings depends largely on the version of Motif
you are using, and the widget target of the string.  The README for the
motif sources indicates which widgets copy strings (allowing you to free
your original) and which ones dont.  Here is an excerpt from my 1.1 source:

}       Compound String Resources Inconsistently Copied
}
}       In this release, XtGetValues for a resource whose value is a
}       compound string sometimes does and sometimes does not copy
}       the returned string.  Following is a list of some known
}       resources whose XmString values are not copied (this list
}       may not be exhaustive):
}
}            XmBulletinBoard     XmNdialogTitle
}            XmFileSelectionBox  XmNdirectory
}                                XmNnoMatchString
}            XmRowColumn         XmNlabelString
}            XmScale             XmNtitleString
}
}       In addition, the XmList resources XmNitems and XmNselectedI-
}       tems, which are of type XmStringTable, are not copied.
}
}       You must be careful not to free the compound strings
}       returned by XtGetValues for these resources; you should free
}       the compound strings returned for other XmString resources,
}       using the XmStringFree routine.

We've been bitten a couple of times by this problem; my understanding
is that it is going away as Motif matures.  

>Also, I'm having scrolled lists that randomly don't appear! That
>is to say that one time the full list will appear with the scrollbar
>and the next time it will appear only as a postage stamp size box
>with no scroll bar or anything. Yet if I click in that little box
>the items are still there because I can select the very first one.
>Anyone seen anything like this before?  
>

Remember that scrolled lists contain a scrolled area widget with a
list widget as its child.  So, for example, if you want to set 
constraints for the list (e.g. setting XmNxxxAttachments in a form)
you have to set the constraints on the PARENT of the list.  The
convenience routine returns the widget ID of the list widget, so
you'de have to do something like this:

  /* create the list box. */

  listBox = XmCreateScrolledList(listForm, "listBox", NULL, NULL);
  
  XtVaSetValues(XtParent(listBox), 
                XmNleftAttachment, XmATTACH_FORM,
                XmNrightAttachment, XmATTACH_FORM,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNallowResize, False,
                NULL);
  XtManageChild(listBox);


Good Luck!

J.R.
-- 
-------------------------------------------------------------------------------
DKW  Systems Corporation
4050 INFOMART
1950 Stemmons Freeway,

marbru@auto-trol.com (Martin Brunecky) (06/25/91)

In article <1991Jun20.233458.16196@dkwgate.uucp> jr@dkwgate.uucp (J.R. Jesson) writes:
>
>}       Compound String Resources Inconsistently Copied
>
>We've been bitten a couple of times by this problem; my understanding
>is that it is going away as Motif matures.  
>
   Can you quote the source for your understanding ? Also, what do
   you mean by "going away": it will be documented, it will be
   changed to be consistent, you will never be required to free it
   (as with any other "pointer" type resources) ?



-- 
=*= Opinions presented here are solely of my own and not those of Auto-trol =*=
Martin Brunecky                      marbru%auto-trol@sunpeaks.central.sun.com
(303) 252-2499                       (better avoid:  marbru@auto-trol.COM )
Auto-trol Technology Corp. 12500 North Washington St., Denver, CO 80241-2404