Autorelease just removes a retain count from the object it does not "free" the memory immediately like in c. When the autorelease pool ends all auto released objects with a count of 0 will have their memory freed up.
Sometimes you create a lot of objects. An example would be a loop that is creating new strings every time it iterates and adds new data to the string. You may not need the previous versions of the string and will want to free up memory used by those. You can accomplish this by explicitly using the autorelease pool instead of waiting for it to be done naturally.
//Note: answers are psudocode
//Non Arc Env
@autoreleasepool
{
MyObject *obj = [[MyObject alloc] init]; // no autorelease call here
//Since MyObject is never released its a leak even when the pool exits
}
//Non Arc Env
@autoreleasepool
{
MyObject *obj = [[[MyObject alloc] init] autorelease];
//Memory is freed once the block ends
}
// Arc Env
@autoreleasepool
{
MyObject *obj = [[MyObject alloc] init];
//No need to do anything once the obj variable is out of scope there are no strong pointers so the memory will free
}
// Arc Env
MyObject *obj //strong pointer from elsewhere in scope
@autoreleasepool
{
obj = [[MyObject alloc] init];
//Not freed still has a strong pointer
}