memory leaks - Objective-C @autoreleasepool? -


i new obj-c , starting out making little useless programs further knowledge. wanted make sure wasn't making memory leaks. in '@autoreleasepool' automatically release it's memory when program ends?

also if there bad habits, please let me know!

int main(int argc, const char * argv[]) {     @autoreleasepool {          fraction* fractionone = [[fraction alloc]init];         fraction* fractiontwo = [[fraction alloc]init];         fraction* fractionthree = [[fraction alloc]init];          [fractionone setto:1 over:2];         [fractiontwo setto:1 over:4];         [fractionthree setto:1  over:8];          [fraction numberoffractions];      return 0;     } } 

see apple's discussion of using autorelease pool blocks in advanced memory management programming guide.

in short, no, not case "anything in @autoreleasepool automatically release[s] memory when program ends" (or @ least not function of @autoreleasepool). purpose in having autorelease pool control when memory reclaimed autorelease items, i.e. when pool drained. code sample doesn't appear employ autoreleased items, not applicable here (unless methods used autorelease objects internally).

the common usage of autorelease pools reduce memory high-water mark of app. see use local autorelease pool blocks reduce peak memory footprint. used used thread programming, have operation , dispatch blocks, don't have write traditional threaded code anymore, don't have many occasion need separate autorelease pools in our multithreaded code.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -