Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!mailrus!cornell!uw-beaver!ubc-cs!kiwi!dssmv2!jaccard From: jaccard@dssmv2.mpr.ca (Philippe Jaccard) Newsgroups: comp.windows.x.motif Subject: Motif List boxes Message-ID: <2304@kiwi.mpr.ca> Date: 17 Aug 90 23:23:39 GMT Sender: news@eric.mpr.ca Reply-To: jaccard@dssmv2.UUCP (Philippe Jaccard) Organization: Microtel Pacific Research Ltd., Burnaby, B.C., Canada Lines: 95 I have an application which wishes to dynamically set the items of a list upon command. I've used the XtSetValues function to set the XmNitems and XmNitemCount property. As the number of Items is highly variable, I need to allocate/deallocate memory each time a Initialize the list contents. I allocate memory to store the array of Xmstring which contents the items and I call the XtSetValues to store the Items in the List. I keep a pointer to this array so I can free it before setting a new one. It runs great but the size of my executable grows as long as I work with the list (memory leak). Does anybody know what does MOTIF do with this array of XmSrring ? Does the XmList object make an internal copy ? How do the XmListAddItem and XmListDeleteItem access the list ? Is XmListDeleteItem the only way to Free the memory space allocated for the items ? . . . Any Ideas people? Philippe Here follows part of the code(C++) I wrote to access the XmList. CreateArrayOfString(DoubleLinkedList* list, int &item_count) { // CreateArrayOfString XmString* string_array; // Get the list's size int size = list->GetSize(); // if the list is empty, just return an empty string. if(size<=0) { // Create an empty string string_array = CreateNong[size+1]; } // Create an empty string else { // create the array of string string_array = new XmString[size+1]; list->MoveToHead(); for(int i=0; iGetCurrentNode(); string_array[i] = XmStringCreate((char*)node->GetData(), (XmStringCharSet)XmSTRING_DEFAULT_CHARSET); // Move the current pointer on the following node list->MoveToNext(); } // copy all nodes string_array[size] = NULL; } // create the array of string // return the item_count item_count = size; return string_array; } //CreateArrayOfString void SetListItems(Widget list, XmString* new_string, int element_count) { // SetListItems Arg arg[3]; // Replace it with the new list and set the XmNitemCount. int i = 0; XtSetArg(arg[i], XmNitems, (XtArgVal)(new_string)); i++; XtSetArg(arg[i] ,XmNitemCount, (XtArgVal)element_count); i++; XtSetValues(list, arg, i); } // SetListItems void FreeArrayOfString(XmString* string_array, int element_count) { // FreeArrayOfString int i = 0; while(i <= element_count) { // free the string XmStringFree(string_array[i]); i++; } // free the string // Deallocate the array of string delete string_array; } // FreeArrayOfString