Assume I have a code like this:
@autoreleasepool {
for(int i = 0; i < relatedSlideDecks.count; i++) {
MyClass *myObject = [MyClass new];
... something happens here
[myObject release];
{
}
do I still need that [myObject release];? Or will it be autoreleased because of @autoreleasepool?
It is still a requirement to release
myObjectbecause the@autoreleasepoolblock does not change the memory management rules, which state that you must relinquish ownership of objects you own, and you ownmyObject. The one thing you can’t do is use an object that was autoreleased within an@autoreleasepoolblock outside of that block. It is useful if you have a small section of your program that may create a lot of autoreleased objects that need to be released as soon as possible rather than until the main autorelease pool is drained.