Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-05-2009, 01:59 PM   #10 (permalink)
FlyingDiver
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
Default

Quote:
Originally Posted by MatuX View Post
Thanks a lot for all your answers, they are helping me a lot for sure!!!

On another note, I'm reading about the Autorelease pool. Did I understand this correctly?
Code:
-(void)myFunc
{
 NSAutoreleasePool * myOwnPool = [[NSAutoreleasePool alloc] init];
 Obj o1 = [[Obj alloc] init];
 Obj o2 = [[Obj alloc] init]; 
 Obj o3 = [[Obj alloc] init];

 [whateverOtherObject setObj:o1]; //obj/setObj property set to retain
 [whateverObject setObj:o2 andObj:o3]; //obj/setObj property set to retain

 [myOwnPool release];
}
Would this automatically release o1, o2, o3 and still keep the memory allocated for "whateverOtherObject" and "whateverObject"?

Thanks!
No, because none of those objects were marked for autorelease. If you had done:

Code:
-(void)myFunc
{
 NSAutoreleasePool * myOwnPool = [[NSAutoreleasePool alloc] init];
 Obj o1 = [[[Obj alloc] init] autorelease];
 Obj o2 = [[[Obj alloc] init] autorelease]; 
 Obj o3 = [[[Obj alloc] init] autorelease];

 [whateverOtherObject setObj:o1]; //obj/setObj property set to retain
 [whateverObject setObj:o2 andObj:o3]; //obj/setObj property set to retain

 [myOwnPool release];
}
Then the only retains would be by whateverObject, and when it releases o1, o2, and o3, they would get deallocated.

joe
FlyingDiver is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,330
Threads: 39,128
Posts: 171,556
Top Poster: smasher (2,577)
Welcome to our newest member, yeurh121
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.