Re: Newbie with stupid question cont.
Re: Newbie with stupid question cont.
- Subject: Re: Newbie with stupid question cont.
- From: email@hidden
- Date: Mon, 18 Mar 2002 22:32:47 -0800
BTW, little question. If I do:
NSString *bla = [aString substringFromIndex:5];
Do I need to send a release to bla?
No, and if you do (and nobody else does a balancing retain), you'll
get a crash when the autorelease pool pops. "bla" is autoreleased, like
all other objects that you didn't explicitly create via alloc, new, copy
and related methods.
I'm asking because the following code crash if I uncomment the [sReturn
release]:
- (NSArray *) getInterfaceIPList{
NSArray *ifaces;
NSMutableArray *arrReturn;
NSString *sReturn;
int x;
ifaces = [self getInterfaceList];
arrReturn = [NSMutableArray arrayWithCapacity:[ifaces count]];
for(x=0 ; x < [ifaces count]; x++){
sReturn = [NSString stringWithFormat:@"%@ (%@)", [ifaces
objectAtIndex:x], [self getIPForInterface:[ifaces objectAtIndex:x]]];
[arrReturn addObject:sReturn];
[sReturn release]
}
return arrReturn;
}
Yep. Symptoms would vary depending upon the lifetime of arrReturn
versus the time to the next pop of the autorelease pool, but this should
crash eventually in one way or another.
Ben Haller
Stick Software
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.