Carl,

I've expanded examples/tests/addrows.c so it does the sequence you
describe if you hit the button.

I've used memprof to scan for leaks. I've saved the leak info three
times :
- after program startup (memprof.leak1)
- after hitting the button (memprof.leak2)
- after terminating the program with the WM_CLOSE button (memprof.leak3)

The three files are identical :
-rw-rw-r--  1 danny backx   6202 Dec  4 15:53 memprof.leak1
-rw-rw-r--  1 danny backx   6202 Dec  4 15:53 memprof.leak2
-rw-rw-r--  1 danny backx   6202 Dec  4 15:53 memprof.leak3

I'm attaching one for your reference, and the modified addrows.c
to save you the trouble of getting it from CVS.

Based on this, my guess is that the leak is not in XbaeMatrix.

I'm doing this on a PC with Mandrake 10.0 and LessTif 0.94.0 .

        Danny

On Wed, 2004-12-01 at 21:06, Stahl, Carl wrote:
> I've been trying to track down a memory leak in an application and it
> seems like my problem is within XbaeMatrixAddRows.  What I've been
> doing to track memory usage of a process is through this command:
> 
>         ps -ek -opid,ppid,etime,time,vsz,args
> 
> I have a function/driver that adds one row into a matrix using
> XbaeMatrixAddRows then deletes that row by calling
> XbaeMatrixDeleteRows:
> 
>         XbaeMatrixAddRows(Mw, XbaeMatrixNumRows(Mw), str, NULL, NULL,
> 1); 
>         XbaeMatrixDeleteRows(Mw, 0, 1); 
> 
>         /* Mw is the matrix, str contains a fixed size string to be
> displayed in the list */ 
> 
> If I call this function thousands of times, I will see the vsz output
> (memory usage for the process) steadily increase.    I wasn't
> expecting the memory usage to increase because I assumed that 
> XbaeMatrixDeleteRows deleted the row that was created and XtRealloc
> wouldn't malloc more memory since the string size did not change.  
> 
> I ran Insure/Inuse and Valgrind on this driver and both reported no
> heap growth however the ps command shows an increase in memory usage
> over time.  Anyone have any thoughts?  I would really appreciate any
> help you can provide.
> 
> Carl Stahl   
-- 
Danny Backx - danny.backx-at-scarlet.be    http://up.to/danny.backx
/* $Id: addrows.c,v 1.4 2004/12/04 14:54:19 dannybackx Exp $ */

#include <stdlib.h>
#include <stdio.h>

#include <X11/Intrinsic.h>
#include <Xm/Xm.h>

#include <Xbae/Matrix.h> /* for version info */
#include <Xm/Form.h>
#include <Xm/PushB.h>

#define	NUM_ARGS_PER_ROW	5

Widget form, mat;

void doit()
{
	int	num_cmds = 5;
	int	x, y, z;
	int	num_args_in_cmd = 5;
	char buff[30];
      
      char *cmd_labels[] = { "", "TIME",
                           "ARG1",  "ARG2",  "ARG3",  "ARG4",  "ARG5",
                           "ARG6",  "ARG7",  "ARG8",  "ARG9",  "ARG10",
                           "ARG11", "ARG12", "ARG13", "ARG14", "ARG15",
                           "ARG16", "ARG17", "ARG18", "ARG19", "ARG20",
                           "ARG21", "ARG22", "ARG23", "ARG24", "ARG25",
                           "ARG26", "ARG27", "ARG28", "ARG29", "ARG30", "ARG31"
                          };

      short cmd_widths[] = { 12, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
                                  7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
                                  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 };
#if 1
      mat = XtVaCreateWidget ("test_xbae",
                             xbaeMatrixWidgetClass,
                             form,
                             XmNtopAttachment,    XmATTACH_FORM,
                             XmNleftAttachment,   XmATTACH_FORM,
                             XmNbottomAttachment, XmATTACH_FORM,
                             XmNtopOffset, 10,
                             XmNbottomOffset, 100,
                             XmNleftOffset, 10,
                             XmNrightOffset, 10,
                             XmNrightAttachment,  XmATTACH_FORM,
                             XmNcolumns, XtNumber(cmd_labels),
                             XmNcolumnLabels, cmd_labels,
                             XmNcolumnWidths, cmd_widths,
                              XmNrows, 0,
                              NULL);
       XbaeMatrixAddRows(mat, 0, NULL, NULL, NULL, num_cmds); 
#else
      mat = XtVaCreateWidget ("test_xbae",
                             xbaeMatrixWidgetClass,
                             form,
                             XmNtopAttachment,    XmATTACH_FORM,
                             XmNleftAttachment,   XmATTACH_FORM,
                             XmNbottomAttachment, XmATTACH_FORM,
                             XmNtopOffset, 10,
                             XmNbottomOffset, 10,
                             XmNleftOffset, 10,
                             XmNrightOffset, 10,
                             XmNrightAttachment,  XmATTACH_FORM,
                             XmNcolumns, XtNumber(cmd_labels),
                             XmNcolumnLabels, cmd_labels,
                             XmNcolumnWidths, cmd_widths,
                              XmNrows, num_cmds,
                              NULL);
#endif
       for(x = 0; x < num_cmds; x++ )
       {
         printf ("Handling Command #%d\n", x);
     
          sprintf(buff, "Test %d", x);
         XbaeMatrixSetCell(mat, x, 0, buff); 
         sprintf(buff, "Delay %d", x);
         XbaeMatrixSetCell(mat, x, 1, buff); 
         for( y = 0; y < num_args_in_cmd; y++ )
         {
           XbaeMatrixSetCell(mat, x, y+2 , "XX"); 
         }

         for (z = y; z < NUM_ARGS_PER_ROW; z++)
         {
            XbaeMatrixSetCell(mat, x, z+2 , "---"); 
          }

       }
       XtManageChild(mat);
}

void push(Widget w, XtPointer client, XtPointer call)
{
	int	i, ncols;
	char	**str;

	ncols = XbaeMatrixNumColumns(mat);
	str = (char **)XtCalloc(ncols, sizeof(String));
	for (i=0; i<ncols; i++)
		str[i] = "xxx";
	for (i=0; i<100; i++) {
		XbaeMatrixAddRows(mat, XbaeMatrixNumRows(mat), str, NULL, NULL, 1);
		XbaeMatrixDeleteRows(mat, 0, 1);
	}
	XtFree((void *)str);
}

int
main (int argc, char **argv)
{
  Widget toplevel, pb;

  /* Print run-time version of libXbae to stdout */
  printf("Using Xbae %s\n", XbaeGetVersionTxt());
  printf("This example was built with %s\n", XbaeVersionTxt);

  /* Print compile-time version of libXm to stdout */
  printf("Xbae was built with %s\n", XbaeGetXmVersionTxt());
  printf("and is running with %s\n", XmVERSION_STRING);

  toplevel = XtInitialize (argv[0], "Test", NULL, 0, &argc, argv);
  form = XtVaCreateManagedWidget("form", xmFormWidgetClass, toplevel,
	XmNwidth, 	500,
	XmNheight,	400,
	NULL);

  doit();
  
  pb = XtVaCreateManagedWidget("add/delete rows", xmPushButtonWidgetClass, form,
	XmNtopAttachment,	XmATTACH_WIDGET,
	XmNtopWidget,		mat,
	XmNtopOffset,		10,
	XmNleftAttachment,	XmATTACH_FORM,
	XmNleftOffset,		10,
  	NULL);
  XtAddCallback(pb, XmNactivateCallback, push, NULL);
  
  XtRealizeWidget (toplevel);
  XtMainLoop ();

  return (EXIT_SUCCESS);
}
Leaked 0x8080920 (8 bytes)
        XmFontListCopy()
        _XmGetDefaultFontList()
        initialize()
        CallInitialize()
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateManagedWidget()
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x8080910 (12 bytes)
        __XmFontListAlloc()
        XmFontListCopy()
        _XmGetDefaultFontList()
        initialize()
        CallInitialize()
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateManagedWidget()
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x80800d8 (40 bytes)
        _XmFontListEntryCreate()
        __XmFontListAlloc()
        XmFontListCopy()
        _XmGetDefaultFontList()
        initialize()
        CallInitialize()
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateManagedWidget()
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x80791a0 (8 bytes)
        _XmRegionCreate()
        initialize()
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        XtCreateWidget()
        _XmGetDropSiteManagerObject()
        _XmDropSiteWrapperCandidate()
        ResizeWrapper()
        ResizeWrapper4()
        initialize()
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        Initialize(): ../../SOURCES/src/Matrix.c:1231
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        doit(): ../../../SOURCES/examples/tests/addrows.c:37
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x8078978 (20 bytes)
        _XmRegionCreate()
        initialize()
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        XtCreateWidget()
        _XmGetDropSiteManagerObject()
        _XmDropSiteWrapperCandidate()
        ResizeWrapper()
        ResizeWrapper4()
        initialize()
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        Initialize(): ../../SOURCES/src/Matrix.c:1231
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        doit(): ../../../SOURCES/examples/tests/addrows.c:37
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x8075268 (17 bytes)
        read_atoms_table()
        _XmInitTargetsTable()
        _XmTargetsToIndex()
        __XmDSMCreateInfo()
        XmDropSiteRegister()
        Initialize()
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        Initialize(): ../../SOURCES/src/Matrix.c:1361
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        doit(): ../../../SOURCES/examples/tests/addrows.c:37
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x80728b8 (40 bytes)
        _XmFontListEntryCreate()
        __XmFontListAlloc()
        XmFontListCopy()
        Initialize(): ../../SOURCES/src/Matrix.c:1121
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        doit(): ../../../SOURCES/examples/tests/addrows.c:37
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x80728a8 (8 bytes)
        XmFontListCopy()
        Initialize(): ../../SOURCES/src/Matrix.c:1121
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        doit(): ../../../SOURCES/examples/tests/addrows.c:37
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x8072898 (12 bytes)
        __XmFontListAlloc()
        XmFontListCopy()
        Initialize(): ../../SOURCES/src/Matrix.c:1121
        CallInitialize()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        doit(): ../../../SOURCES/examples/tests/addrows.c:37
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x80727b8 (6 bytes)
        XmFontListEntryLoad()
        __XmFontListResourceAddEntry()
        _XmCvtStringToXmFontList()
        CallConverter()
        _XtConvert()
        GetResources()
        _XtGetResources()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        doit(): ../../../SOURCES/examples/tests/addrows.c:37
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x8072788 (40 bytes)
        XmFontListEntryLoad()
        __XmFontListResourceAddEntry()
        _XmCvtStringToXmFontList()
        CallConverter()
        _XtConvert()
        GetResources()
        _XtGetResources()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        doit(): ../../../SOURCES/examples/tests/addrows.c:37
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x80721a8 (28 bytes)
        XmFontListEntryLoad()
        __XmFontListResourceAddEntry()
        _XmCvtStringToXmFontList()
        CallConverter()
        _XtConvert()
        GetResources()
        _XtGetResources()
        xtCreate()
        _XtCreateWidget()
        _XtVaCreateWidget()
        XtVaCreateWidget()
        doit(): ../../../SOURCES/examples/tests/addrows.c:37
        main(): ../../../SOURCES/examples/tests/addrows.c:131
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x806ab18 (23 bytes)
        VirtKeysInitialize()
        _XmVirtKeysInitialize()
        initialize()
        CallInitialize()
        xtCreate()
        _XtAppCreateShell()
        XtAppCreateShell()
        GetXmDisplay()
        XmGetXmDisplay()
        secondary_object_create()
        initialize_prehook()
        InitializeRootWrapper()
        CallInitialize()
        CallInitialize()
        CallInitialize()
        CallInitialize()
        CallInitialize()
        CallInitialize()
        CallInitialize()
        CallInitialize()
        CallInitialize()
        CallInitialize()
        xtCreate()
        _XtAppCreateShell()
        XtAppCreateShell()
        XtOpenApplication()
        XtAppInitialize()
        XtInitialize()
        main(): ../../../SOURCES/examples/tests/addrows.c:123
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105
Leaked 0x8062b08 (28 bytes)
        class_initialize()
        XtInitializeWidgetClass()
        XtInitializeWidgetClass()
        XtInitializeWidgetClass()
        xtWidgetAlloc()
        xtCreate()
        _XtAppCreateShell()
        XtAppCreateShell()
        XtOpenApplication()
        XtAppInitialize()
        XtInitialize()
        main(): ../../../SOURCES/examples/tests/addrows.c:123
        [0x4037e95d]
        _start(): ../sysdeps/i386/elf/start.S:105

Reply via email to