kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) (11/16/90)
I'm pursuing a memory leak problem with a Motif-1.1 based application. The problem occurs when I run the attached program, which creates and destroys widgets repeatedly. I cannot just unmanage and manage because this is a (psuedo) real-time application which will be using thousands of widgets; only those currently needed are created, then destroyed as appropriate. The leak can be triggered (in my situation) with a bogus resource like: Main*kaleb.background Take your pick, you can put the resource in the .Xdefaults, app-defaults, or the XENVIRONMENT file. Note: you can substitute kaleb with anything else you like (I like kaleb, I wonder why?) With the bogus resource, the code in _XtCallConverter() is passed a Converter,which has a cache_type of XtCacheNone, and therefor augments the Translation table (???) with each new create. Stack trace looks like this: _XtCallConverter() ConvertATranslation() XtOverrideTranslations() _XmNavigInitialize() `Manager`Initialize() CallInitialize() CallInitialize() CallInitialize() _XtCreate() _XtCreateWidget() XtCreateWidget() XmCreateForm() If the offending resource specification is deleted, and the program rerun, the converter cache_type is XtCacheAll, and the Translation table is therefor not augmented. Relevent details: Sun 4, SunOS 4.1, SunOS compiler. X11R4.18. Motif-1.1 w/ update-1 and update-2. I realize the above information is probably too sketchy to expect a "solution-by-mail", however, if anyone who understands the Xt internals can shed some light on what is going on, particularly why the bogus resource might cause the Converter cache_type to be what it is? (BTW, strangely enough, I can only produce this leak on Suns running SunOS 4.1. I cannot duplicate under SunOS 4.0.3, or on a Decstation 3100 running Ultrix 4.0. I also tried an Athena widget version; it doesn't leak.) resource file: Main*aaaaa.foreground: black Main*aaaaa.background: cyan Main*bbbbb.foreground: black Main*bbbbb.background: green Main*ccccc.foreground: black Main*ccccc.background: yellow Main*ddddd.foreground: black Main*ddddd.background: red Main*ffff.foreground: black Main*ffff.background: magenta Main*kaleb.background: black source file: #include <X11/Intrinsic.h> #include <Xm/Form.h> #include <Xm/Label.h> #include <Xm/PushB.h> #include <Xm/Separator.h> #include <Xm/Frame.h> #include <fcntl.h> static Widget toplevel, ffff, aaaaa, bbbbb, ccccc, ddddd; static int i = 0; static Arg myargs[10]; void init_args () { XtSetArg (myargs[i], XmNleftAttachment, XmATTACH_POSITION); i++; XtSetArg (myargs[i], XmNleftPosition, 10); i++; XtSetArg (myargs[i], XmNrightAttachment, XmATTACH_POSITION); i++; XtSetArg (myargs[i], XmNrightPosition, 90); i++; XtSetArg (myargs[i], XmNtopAttachment, XmATTACH_POSITION); i++; XtSetArg (myargs[i], XmNbottomAttachment, XmATTACH_POSITION); i++; } void create_aaaaa () { int j = i; XtSetArg (myargs[j], XmNtopPosition, 10); j++; XtSetArg (myargs[j], XmNbottomPosition, 21); j++; aaaaa = XmCreateFrame (ffff, "aaaaa", myargs, j); XtManageChild (aaaaa); } void create_bbbbb () { int j = i; XtSetArg (myargs[j], XmNtopPosition, 32); j++; XtSetArg (myargs[j], XmNbottomPosition, 43); j++; bbbbb = XmCreateSeparator (ffff, "bbbbb", myargs, j); XtManageChild (bbbbb); } void create_ccccc () { int j = i; XtSetArg (myargs[j], XmNtopPosition, 54); j++; XtSetArg (myargs[j], XmNbottomPosition, 65); j++; ccccc = XmCreatePushButton (ffff, "ccccc", myargs, j); XtManageChild (ccccc); } void create_ddddd () { int j = i; XtSetArg (myargs[j], XmNtopPosition, 76); j++; XtSetArg (myargs[j], XmNbottomPosition, 87); j++; ddddd = XmCreateLabel (ffff, "ddddd", myargs, j); XtManageChild (ddddd); } void create_ffff () { int i = 0; Arg myargs[5]; XtSetArg (myargs[i], XmNwidth, 200); i++; XtSetArg (myargs[i], XmNheight, 200); i++; ffff = XmCreateForm (toplevel, "ffff", myargs, i); XtManageChild (ffff); } void time_out (dummy, id) caddr_t dummy; XtIntervalId *id; { XmString string; char *cstring; Arg args[5]; int i = 0; int fd1, fd2, fd3; /* fd1 = open ("befored", O_CREAT | O_WRONLY, 0600 ); malloc_dump (fd1); close (fd1); */ XtDestroyWidget (ffff); create_ffff (); /* create_ddddd (); create_ccccc (); create_bbbbb (); create_aaaaa (); */ XtAddTimeOut (2000, time_out, NULL); } main (argc, argv) int argc; char **argv; { toplevel = XtInitialize ("main", "Main", NULL, 0, &argc, argv); init_args (); create_ffff (); create_ddddd (); create_ccccc (); create_bbbbb (); create_aaaaa (); XtRealizeWidget (toplevel); XtAddTimeOut (10, time_out, NULL); XtMainLoop(); } -- Kaleb Keithley Jet Propulsion Labs kaleb@thyme.jpl.nasa.gov I don't watch Twin Peaks; I just come to work.
meo@rsiatl.UUCP (Miles ONeal) (11/17/90)
This is not a Sun flame - I like them a lot. My experience has been that Sun servers tend to leak memory (apps may, too) after any upgrade in which they are not specifically trying to fix such memory leaks. If they didn't, they will - if they did, it'll get worse. Unless they are trying to fix them - then they do a good job. No idea why, it certainly isn't indicative of the rest of my experience with Sun (or I wouldn't like them so much 8^). Maybe Mr. McNealy placed an anti-Motif virus in the new OS? 8^) 8^) 8^)