Xref: utzoo comp.windows.x:29537 comp.windows.x.motif:1219 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!thyme!kaleb From: kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) Newsgroups: comp.windows.x,comp.windows.x.motif Subject: Deep in the Heart of Xt Message-ID: <1990Nov16.023432.4515@thyme.jpl.nasa.gov> Date: 16 Nov 90 02:34:32 GMT Sender: kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 219 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 #include #include #include #include #include #include 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.