Re: I think I am leaking! :)
Re: I think I am leaking! :)
- Subject: Re: I think I am leaking! :)
- From: "Steven W. Riggins" <email@hidden>
- Date: Sat, 27 Oct 2001 14:33:01 -0700
Andrew,
Thanks for the reply. I moved the entire test into a controller in the main nib. It only shows allocations now, no autoreleases, nothing.
Here is the code to test out. I made an instance of MainController in MainMenu.nib:
@implementation MainController
//awakeFromNib is called when this object is done being unpacked from the nib file;
//at this point, we can do any needed initialization before turning app control over to the user
- (void)awakeFromNib
{
[self setIdleTimer];
}
- (void)leakTest
{
NSURL *lURL;
NSData *lData;
int count;
int loop;
for (loop = 0; loop <= 1; loop++)
{
lURL = [[NSURL allocWithZone:[self zone]] initWithString:@"
http://camimg.discovery.com/space/soho/greensun.gif?ct=382873d4"];
if (!lURL)
goto releaseMem;
lData = [lURL resourceDataUsingCache:NO];
if (!lData)
goto releaseMem;
releaseMem:
[lURL release]; // no longer needed
}
return;
}
- (void)setIdleTimer
{
if (idleTimer) {
[idleTimer invalidate];
idleTimer = nil;
}
//idle = NO;
idleTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(checkIdle:) userInfo:nil repeats:YES];
return;
}
- (void)checkIdle:(id)timer
{
[self leakTest];
}
@end
At 1:40 PM -0700 10/27/01, Andrew Platzer wrote:
>
On Saturday, October 27, 2001, at 01:48 , Steven W. Riggins wrote:
>
>I call this from windowDidLoad in my NSWindowController subclass.
>
>When looking at my app with ObjectAlloc, I see 51 NSHTTPURLHandles. Looking in the instance browser tab, I see two events per instance, an AllocationEvent and an ObjectAutoreleasedEvent, but no release/dealloc.
>
>This is boiled down from my larger issues, but trying to find out how I should be releasing the data from the NSURL has become an obsession :)
>
>
I'm surprised that you get an AllocationEvent and an ObjectAutoreleasedEvent but no subsequent actual release. It's as though the autorelease pool isn't being freed. This should happen each time you return from handling an event in NSApplication. I looked through the NSURL and NSHTTPURLHandle and didn't see any obvious leaks.
>
>
Check with MallocDebug or the leaks tool to see if the objects are really leaked or someone is holding on to an extra reference. If not, try putting your own NSAutorelease pool around the loop and see if that helps.