Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Will this cause a leak?



I'm a little confused with the concept of autorelease, I've read all the documentation about the topic that has been posted thus far in the forum and I find myself still confused.  Can someone perhaps still clarify.

For example if I had the following:

-(NSString*) Foo
{
	NSString *myString  = [[NSString alloc] initWithString:@"This is a test"];  //at this point retainCount = 1
	return [myString autorelease]; //Have I leaked?
}

>From experimentation, I have found that autorelease does not decrement the retain count, if anything it will increment the retain count.
So do I need to explicitly call [release] on the object before returning out of the method?  Should my code be changed to look like:

[myString autorelease];
[myString release];
return myString

thanks for the help...
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.