[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference hydra::axp-developer

Title:Alpha Developer Support
Notice:[email protected], 800-332-4786
Moderator:HYDRA::SYSTEM
Created:Mon Jun 06 1994
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3722
Total number of notes:11359

3343.0. "SEMA Group (grenoble) - point 23195" by RDGENG::ASAP () Tue Mar 18 1997 10:34

    Contact Name :  jean Michel ROCHE
    Phone        :  (1) 43 94 57 10
    Fax          :  (1) 43 94 57 93
    Email        :  [email protected]
    Date/Time in :  18-MAR-1997 15:32:34
    Entered by   :  Richard Readings
    SPE center   :  REO

    Category     :  unix
    OS Version   :  3.2c
    System H/W   :  


    Brief Description of Problem:
    -----------------------------
SEMA GROUP is situated at:
56 Rue R. Salengro
94120 Fontenay/bois
France

PH: (1) 43 94 57 10
FAX:(1) 43 94 57 93


from : jean Michel ROCHE Sema Group GRENOBLE (FRANCE)
       [email protected]

hello,

We have some problems with dynamic MOTIF widget creation and destruction, it
seems that this action makes 
memory consumption

environment :
-------------
Digital UNIX V3.2C  (Rev. 148); Mon Aug 12 10:39:49 MET DST 1996
Digital UNIX V3.2C Worksystem Software (Rev. 148)


We write a little bench to show the problem
I send you the program : tow files : test_mopo.uil and test_mopo.c

make by :
cc test_mopo.c -threads -D_SHARED_LIBRARIES -Dalpha -D_REENTRANT -lX11 -lXt
-lXm -lMrm -o test_mopo
/usr/bin/X11/uil -w -o test_mopo.uid test_mopo.uil

run by :
test_mopo

test_mopo.uil :
---------------

!------------------------------------------------------------------------------
-
module TEST_MOPO
    names = case_sensitive

!------------------------------------------------------------------------------
-
procedure
        cb_create_mopo_form();
!------------------------------------------------------------------------------
-
object MOPO_FORM : XmForm
        {
    arguments
        {
        XmNwidth                    = 400;
        XmNheight                   = 1000;
        XmNresizePolicy             = XmRESIZE_NONE;
        };
    callbacks
        {
        MrmNcreateCallback          = procedure cb_create_mopo_form();
        };
    };
!------------------------------------------------------------------------------
-
object MOPO_BUTTON : XmPushButton
    {
    arguments
        {
        XmNshadowThickness          = 2;
        XmNborderWidth              = 0;
        XmNlabelType                = XmSTRING;
        XmNlabelString              = "TEST";
        XmNx                        = 10;
        XmNy                        = 10;
        };
    };
!------------------------------------------------------------------------------
-
object MOPO_SCALE : XmScale
    {
    arguments
        {
        XmNx                        = 10;
        XmNy                        = 100;
        XmNshowValue                = true;
        XmNmaximum                  = 400;
        XmNminimum                  = 100;
        XmNdecimalPoints            = 1;
        XmNorientation              = XmHORIZONTAL;
        };
    };
!------------------------------------------------------------------------------
-
object MOPO_TEXT : XmText
    {
    arguments
        {
        XmNx                        = 10;
        XmNy                        = 200;
        XmNwidth                    = 100;
        };
    };

end module;


test_mopo.c :
-------------

/*----------------------------------------------------------------------------*
/
#include <stdio.h>
#include <Xm/Xm.h>          /* Motif Toolkit */
#include <Mrm/MrmPublic.h>   /* Mrm */

static MrmHierarchy	s_MrmHierarchy;		/* MRM database hierarch id */
static char		    *vec[]={"test_mopo.uid"};
						/* MRM database file list   */
static MrmCode		class ;

static void cb_create_mopo_form();

static MrmCount		  regnum = 1 ;
static MrmRegisterArg regvec[] = {
	{"cb_create_mopo_form",(XtPointer)cb_create_mopo_form}
	};

static void cb_cyclique();

Display  	    *display;
XtAppContext  	app_context;

Widget toplevel, test_mopo_main;
Arg arglist[1] ;
int n;
XEvent event;

Widget tab_widget[30];
int i;
int etat = 0;

/*----------------------------------------------------------------------------*
/
int main(argc, argv)
     int    argc;
     String argv[];
{
	XtIntervalId timer;

	printf ("MrmInitialize\n");
    	MrmInitialize ();

	printf ("XtToolkitInitialize\n");
    	XtToolkitInitialize();

	printf ("XtCreateApplicationContext\n");
    	app_context = XtCreateApplicationContext();

	printf ("XtOpenDisplay\n");
    	display = XtOpenDisplay(app_context, NULL, argv[0], "test_mopo_class",
                            NULL, 0, &argc, argv);
    	if (display == NULL) {
        	fprintf(stderr, "%s:  Can't open display\n", argv[0]);
        	exit(1);
    	}

	printf ("XtAppCreateShell\n");
    	n = 0;
    	XtSetArg(arglist[n], XmNallowShellResize, True);  n++;
    	toplevel = XtAppCreateShell(argv[0], NULL, applicationShellWidgetClass,
                              display, arglist, n);

	printf ("MrmOpenHierarchy\n");
    	if (MrmOpenHierarchy (1,	
			vec, 			    
			NULL,			    
			&s_MrmHierarchy)	
			!= MrmSUCCESS) {
		printf ("can't open hierarchy\n");
     	}

    	if (MrmRegisterNames (regvec, regnum)
			!= MrmSUCCESS)
			    printf("can't register names\n");

    	if (MrmFetchWidget (s_MrmHierarchy,
			"MOPO_FORM",
			toplevel,
			&test_mopo_main,
			&class)
			!= MrmSUCCESS)
			    printf("can't fetch interface\n");
		printf ("XtManageChild\n");
    	XtManageChild(test_mopo_main);

	printf ("XtRealizeWidget\n");
    	XtRealizeWidget(toplevel);


	printf ("XtAppAddTimeOut\n");
	timer = XtAppAddTimeOut(
    	app_context,
		1000,
		cb_cyclique,
		NULL);

	printf ("XtAppMainLoop\n");
    	XtAppMainLoop(app_context);
}

/*----------------------------------------------------------------------------*
/
static void cb_create_mopo_form( widget, tag, callback_data )
	Widget	widget;
	char    *tag;
	XmAnyCallbackStruct *callback_data;
{
	printf("cb_create_mopo_form\n");
}

/*----------------------------------------------------------------------------*
/
static void cb_cyclique(int i, XtIntervalId tim)
{
	XtIntervalId timer;
	Arg list[4];

	printf("cb_cyclique\n");

	if (etat == 0)
	{
		etat = 1;

		for(i=0; i<10; i++)
		{
		    	printf("fetch\n");
    	    		if (MrmFetchWidget(
            	    		    s_MrmHierarchy,
				    "MOPO_SCALE",
				    test_mopo_main,
				    &tab_widget[i],
				    &class)
				    != MrmSUCCESS)
				    printf("can't fetch\n");

            		XtSetArg(list[0], XmNx, 10);
            		XtSetArg(list[1], XmNy, 10 + i*40);
            		XtSetArg(list[2], XmNwidth, 200);
            		XtSetArg(list[3], XmNheight, 35);

            		XtSetValues(
			    tab_widget[i],
			    list,
			    4);

	            	XtManageChild(tab_widget[i]);
		}
	}
	else if (etat == 1)
	{
		etat = 2;

		for(i=0; i<10; i++)
		{
			printf("XtDestroyWidget\n");
			XtDestroyWidget(
				tab_widget[i]);
		}
	}
	else if (etat == 2)
	{
		etat = 3;

		for(i=0; i<20; i++)
		{
		    	printf("fetch\n");
    	    		if (MrmFetchWidget(
            	    		    s_MrmHierarchy,
				    "MOPO_TEXT",
				    test_mopo_main,
				    &tab_widget[i],
				    &class)
				    != MrmSUCCESS)
				    printf("can't fetch\n");

            		XtSetArg(list[0], XmNx, 10);
            		XtSetArg(list[1], XmNy, 10 + i*40);
            		XtSetArg(list[2], XmNwidth, 100);
            		XtSetArg(list[3], XmNheight, 35);

            		XtSetValues(
			    tab_widget[i],
			    list,
			    4);

            		XtManageChild(tab_widget[i]);
		}
	}
	else if (etat == 3)
	{
		etat = 4;

		for(i=0; i<20; i++)
		{
			printf("XtDestroyWidget\n");
			XtDestroyWidget(
				tab_widget[i]);
		}
	}
	else if (etat == 4)
	{
		etat = 5;

		for(i=0; i<30; i++)
		{
		    	printf("fetch\n");
    	    		if (MrmFetchWidget(
            	    		    s_MrmHierarchy,
				    "MOPO_BUTTON",
				    test_mopo_main,
				    &tab_widget[i],
				    &class)
				    != MrmSUCCESS)
				    printf("can't fetch\n");

            		XtSetArg(list[0], XmNx, 10);
            		XtSetArg(list[1], XmNy, 10 + i*30);
            		XtSetArg(list[2], XmNwidth, 70);
            		XtSetArg(list[3], XmNheight, 25);

            		XtSetValues(
			    tab_widget[i],
			    list,
			    4);

            		XtManageChild(tab_widget[i]);
		}
	}
	else if (etat == 5)
	{
		etat = 0;

		for(i=0; i<30; i++)
		{
			printf("XtDestroyWidget\n");
			XtDestroyWidget(
				tab_widget[i]);
		}
	}

	timer = XtAppAddTimeOut(
    	app_context,
		1000,
		cb_cyclique,
		NULL);
}
	


We run this bench for one night, and on the morning it is impossible to stop
this bench (by ctrl c), we
must reboot the computer !!!

memory consumption looking by ps uw

vsu65.sema-grenoble.fr> date
Wed Mar 12 16:34:42 MET 1997
vsu65.sema-grenoble.fr> ps uw
USER       PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME COMMAND
jmr       3894  8.0  1.8 7.62M 1.1M ttyp1    S  + 16:32:42     0:13.63
test_mopo
vsu65.sema-grenoble.fr> date
Wed Mar 12 16:35:54 MET 1997
vsu65.sema-grenoble.fr> ps uw
USER       PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME COMMAND
jmr       3894 14.0  2.0 7.88M 1.2M ttyp1    R  + 16:32:42     0:22.29
test_mopo
vsu65.sema-grenoble.fr> date
Wed Mar 12 16:40:04 MET 1997
vsu65.sema-grenoble.fr> ps uw
USER       PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME COMMAND
jmr       3894 11.0  2.3 7.88M 1.4M ttyp1    S  + 16:32:42     0:53.91
test_mopo
vsu65.sema-grenoble.fr> date
Wed Mar 12 17:28:01 MET 1997
vsu65.sema-grenoble.fr> ps uw
USER       PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME COMMAND
jmr       3894 14.0  2.7 11.4M 1.7M ttyp1    S  + 16:32:42     8:31.99
test_mopo
vsu65.sema-grenoble.fr> date
Wed Mar 12 18:09:14 MET 1997
vsu65.sema-grenoble.fr> ps uw
USER       PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME COMMAND
jmr       3894 17.0  3.1 14.6M 1.9M ttyp1    S  + 16:32:42    17:20.79
test_mopo
vsu65.sema-grenoble.fr> date
Thu Mar 13 08:30:58 MET 1997
vsu65.sema-grenoble.fr> ps uw
USER       PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME COMMAND
jmr       3894 38.0  7.8 44.1M 4.9M ttyp1    R  + 16:32:42    06:45:50
test_mopo
 
Where is the problem ???

Thank you
Good bye



 Kevin Mannerings			                                       
     
 Technical Support Specialist                         FAX:    DTN 822 4445  
 European Customer Service Centre                     Phone:  DTN 822 4320  
 Digital Equipment International B.V.  E-Mail: [email protected] 

T.RTitleUserPersonal
Name
DateLines
3343.1Reply to customerRDGENG::READINGS_RRichard ReadingsWed Mar 19 1997 10:178
I've run your code example (thanks) and reproduced the problem. 

Creating and destroying widgets repeatedly in this way always leads to
memory "leaks". This is considered a feature of X and not a bug. 

We strongly recommend that you re-use widgets instead of destroying then
re-creating them. You should unmanage them, redefine their properties,
and re-manage them.