Memory Leak in Motif 1.0 Dialog Widgets (Interactive port)

Bruce M Ong DeadHead at cup.portal.com
Sat Sep 29 13:46:08 AEST 1990


	hi world -

	I seem to have run into a show stopper for a MOTIF project I am
working on... here is the  deal:

	The motif dialog widget - the selection box dialog -  does
not seem to clean up its internal data when a new XtSetArg() is called
with  a different item count and a different item list than the previous call.

	The following is a short program that produces this problem:

-------------------------
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xutil.h>
#include <Xm/Xm.h>
#include <Xm/SelectioB.h>
#include <Xm/BulletinB.h>

Widget s;

void cb(w,id)	/* cyclic timeout call back */
Widget w;
XtIntervalId id; 
{
 
        XmString item;
        int n;
        Arg wargs[3];
         
        item= XmStringCreateLtoR("item1",XmSTRING_DEFAULT_CHARSET);  
 
        n = 0;

        XtSetArg(wargs[n],XmNlistItems,&item);n++;
        XtSetArg(wargs[n],XmNlistItemCount,1);n++;
        XtSetValues(s,wargs,n);
        XmStringFree(item);
 
        XtManageChild(s);
        XtAddTimeOut(1000,cb,NULL);
}

main(argc, argv) 
int argc;
char *argv[];
{
 
        Widget parent;
        Widget bb;
         
        parent = XtInitialize(argv[0],"test",NULL,0,&argc, argv);
        bb = XtCreateManagedWidget("bb",xmBulletinBoardWidgetClass,
                parent,NULL,0);
        s = XmCreateSelectionDialog(parent,"sbox",NULL,0); 
	/*
	 * add a cyclic timeout 
	 */
        cb(s,NULL);
        XtRealizeWidget(parent);
	XtMainLoop();
}

/* the cyclic timeout is something that i *have* to use in my real program -
   which basically wakes up every n seconds and checks to see if a disk
   directory contains any files. If the directory does contain files, it
   displays the directory file names in the selection box */

--------------------------------
And here is my  ps -el output on systemV (interactive unix 2.0.2) for
this program ("test") - the script I used to produce this data is

#!/bin/csh
while (1)
	ps -el | grep test >> /tmp/data
	sleep 30
end

-----------------
					   Memory Usage
					      |
10 S   212  1692   423 19  26 24   40256c    302 d00b9c08 ttyp2    1:03 test
10 S   212  1692   423 17  26 24   40256c    308 d00b9c08 ttyp2    1:08 test
10 S   212  1692   423 18  26 24   40256c    314 d00b9c08 ttyp2    1:13 test
10 R   212  1692   423 11  69 24   40256c    320          ttyp2    1:18 test
10 R   212  1692   423 24  76 24   40256c    326          ttyp2    1:23 test
10 R   212  1692   423 15  71 24   40256c    332          ttyp2    1:27 test
10 R   212  1692   423 18  72 24   40256c    338          ttyp2    1:32 test
10 R   212  1692   423 25  76 24   40256c    344          ttyp2    1:37 test
10 S   212  1692   423 18  26 24   40256c    350 d00b9c08 ttyp2    1:42 test
10 S   212  1692   423 20  26 24   40256c    355 d00b9c08 ttyp2    1:47 test
10 R   212  1692   423 17  72 24   40256c    361          ttyp2    1:52 test
10 S   212  1692   423 20  26 24   40256c    367 d00b9c08 ttyp2    1:57 test
10 R   212  1692   423 18  73 24   40256c    373          ttyp2    2:02 test
10 R   212  1692   423 23  75 24   40256c    379          ttyp2    2:07 test
10 R   212  1692   423 20  74 24   40256c    385          ttyp2    2:12 test

as we can see, there does seem to be a memory leak. But what I am not sure
is if there is something that I am doing wrong, or if it is a MOTIF problem.
I have not checked the behavior of the widgets not managed under a dialog shell
and see if changing their item list (i.e. for file selection box widget,
list widget, selection box widget, etc.) will cause the same problem. If there
is a memory leak there, then that means if you leave your program running long
enough, it will run out of memory...

any hints and ideas would be much appreciated.  Thanks!

(please email)
-------

bruce
deadhead at cup.portal.com



More information about the Comp.unix.sysv386 mailing list