🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #414

Freeing from Storage object / AcceptWindow = bad example?

#414
From: Ralph Zazula
Date: Mon, 03 Aug 1992 09:02
58 lines
2324 bytes
Howdy!

I'm looking for some info on freeing objects that have been placed into a  
Storage object.  The canonical example for this appears to be the AcceptWindow  
class in the ToolInspector demo.  The -free method for this class is this:

- free
{
    int    i;
    i = [viewRectList count];
    while (i--) {
      free([viewRectList elementAt:i]);
    }
    [viewRectList free];    
    return [super free];
}

and the elements are added to the Storage instance (viewRectList) like so:

    newViewRect = (ViewRectPair *)malloc(sizeof(ViewRectPair));
    ...
    [viewRectList addElement:newViewRect];

where a "ViewRectPair" is:

typedef struct _ViewRectPair 
{
	id	view;
	NXRect	rect;
} ViewRectPair;

Okay, so this is the background.  Now the question: why does this not appear to  
work?  I'm seeing a few things when using this.  First, MallocDebug reports  
each of the malloc'ed VRP's as leaking, as in:

 default  0x0079fd80     20     -[AcceptWindow registerRect:forView:]

Then, when I go through the -free method (with MallocDebug compiled in) I get a  
"freed unmalloced pointer" message for each call to free() in -free.  Finally,  
an app using the AcceptWindow crashes in grand fashion when continuing after  
freeing the the AcceptWindow.  The crashes tend to occur in differing remote  
parts of the app, usually during some type of memory allocation.

For now, I've just ended up freeing only the Storage instance and letting the  
VRP's leak away...  (i.e., removed all calls to free() in AcceptWindow's -free)  
and this seems to stop the app from crashing.

So, is there a problem with AcceptWindow's -free method?  Or, could there be  
something else strange going on here?

Thanks,
Ralph

---
Ralph Zazula
zazula@pri.com (NeXT Mail)
Pinnacle Research, Inc.
Technical Details
Message-ID: <1992Aug3.020248.3570@arizona.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!usc!noiro.acs.uci.edu!cerritos.edu!arizona.edu!arizona.edu!news

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!usc!noiro.acs.uci.edu!cerritos.edu!arizona.edu!arizona.edu!news
Newsgroups: comp.sys.next.programmer
Subject: Freeing from Storage object / AcceptWindow = bad example?
Message-ID: <1992Aug3.020248.3570@arizona.edu>
From: zazula@pri.com (Ralph Zazula)
Date: 3 Aug 92 02:02:47 MST
Reply-To: zazula@pri.com
Distribution: world,local
Keywords: Storage object, free(), crash, burn...
Nntp-Posting-Host: bonehead.tucson.az.us
Lines: 58