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

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

888.0. "XtFree bug?" by WJG::GUINEAU () Tue Jun 06 1989 15:51

    <<< HARBOR::SHPLOG$DUA1:[NOTES$LIBRARY]DECWINDOWS_PROGRAMMING.NOTE;1 >>>
                    -< DECwindows Programming hints/kinks >-
================================================================================
Note 304.0                    XtFree  memory leak?                    No replies
WJG::GUINEAU                                         28 lines   6-JUN-1989 13:56
--------------------------------------------------------------------------------

I'm trying to track down a memory leak in a application I'm writing.

Is this the proper way to use DwtLatin1String()?

{
DwtCompString  s;

s = DwtLatin1String("Make this compound!");

/* Use s for whatever (in my case, setarg on a label name */

XtFree((char *)s);

}


This code gets executed ALOT (every 5-10 seconds)

The symptom is when this code (and a bunch more of the same) is executed, the
working set of the process grows continuously until "insufficient virtual 
memory" happens.

If I comment out this section of code, the WS stays the same...


John


T.RTitleUserPersonal
Name
DateLines
888.1need more infoPSW::WINALSKICareful with that VAX, EugeneTue Jun 06 1989 18:157
That ought to work, although you don't need the char * type cast.  I think the
problem must be in the "Use s for whatever" code.  Can you give an example of
some of the "whatevers" that are causing trouble?  Do they involve any other
calls to compound string routines?

--PSW

888.2More Info WJG::GUINEAUWed Jun 07 1989 07:4347

Here's an example from the code:


void DWS_UpdateHumidity(char *hsb,char *hrb,char *hdb)
{
DwtCompString hs,hr,hd;


hs = DwtLatin1String(hsb);
hr = DwtLatin1String(hrb);
hd = DwtLatin1String(hdb);

SetLabel(cb_h_set,hs);
SetLabel(cb_h_act,hr);
SetLabel(cb_h_dev,hd);

XtFree((char *)hs);
XtFree((char *)hr);
XtFree((char *)hd);

}



hsb, hrb and hdb are all strings created by sprintf() and passed to this
function.

SetLabel is a macro:

#define SetLabel(w,t)           DWS_SetArg(W_list[(w)],DwtNlabel,(t))

and here is DWS_SetArg()



void DWS_SetArg(Widget w, char *resource, char *value)
{
Arg al[1];

XtSetArg(al[0], resource, value);
XtSetValues(w, al, 1);
}



888.3That part looks OKPSW::WINALSKICareful with that VAX, EugeneWed Jun 07 1989 12:214
Please post the code for SetLabel.

--PSW

888.4SetLabel codeWJG::GUINEAUWed Jun 07 1989 18:0323
It's a macro:

#define SetLabel(w,t)           DWS_SetArg(W_list[(w)],DwtNlabel,(t))



and here is DWS_SetArg()



void DWS_SetArg(Widget w, char *resource, char *value)
{
Arg al[1];

XtSetArg(al[0], resource, value);
XtSetValues(w, al, 1);
}



John

888.5it all looks OK to mePSW::WINALSKICareful with that VAX, EugeneWed Jun 07 1989 18:355
Well, that's the way it's supposed to work, to the best of my knowledge.  It
doesn't look like your code is dropping any compound strings on the floor.
This sounds like a memory leak either in XtFree or in the label widget.  I
suggest QARing a simple complete example program that illustrates the problem.

888.6Sounds goodWJG::GUINEAUThu Jun 08 1989 18:384
Thanks Paul.


888.7More on memory leakWJG::GUINEAUThu Jun 15 1989 13:0933
I haven't had time to QAR this yet (been out of town), but today I did get
to isolate it. It's in the call to the SetLabel macro, which is as follows:

#define SetLabel(w,t)           DWS_SetArg(W_list[(w)],DwtNlabel,(t))

DWS_SetArg is this:

void DWS_SetArg(Widget w, char *resource, char *value)
{
Arg al[1];

XtSetArg(al[0], resource, value);
XtSetValues(w, al, 1);
}


The widget in question is a pushbutton (which I used because of it's 
nice look!. I don't use it [them] as a pushbutton, just a display
element to show the current values of a dynamic setpoint).

Anyway, it appears the widget is eating up memory for it's label name. 

I suspect that on every call to XtSetValues for the DwtNlabel, it simply
allocates more memory without freeing previously allocated "label name"
memory.  Could the pushbutton widget owner check on this?

I will QAR it when I get together a smaller program to demonstrate it.

I'm going to try switching to another widget (label?) to see what happens...

John

888.8label does the sameWJG::GUINEAUThu Jun 15 1989 14:079
I switched to using a label widget. Same results.

BTW - It sure is easy changing this kind of thing in UIL. Literally
changing all the appropriate "push_button" object names to "label"
and then adding one other resource value:  border_width = 2;

John

888.9WJG::GUINEAUThu Jun 15 1989 15:409
ALl right, so about the only work-around I can figure is to free the label
storage myself. 

Anyone have the struct definition for  a label widget?


John

888.10QAR # 02919 in DECwindows-IFTWJG::GUINEAUFri Jun 16 1989 08:412