I was reading the documentation from apple about memory management when I got to autorelease pool blocks and something got me thinking.
Any object sent an autorelease message inside the autorelease pool block is
released at the end of the block.
I am not sure I fully understand this. Any object created inside an autorelease pool block gets released at the end of the block anyway because that is it's life span. Why would you need to call autorelease to the object when it is going to get released anyway when it reaches the end of the block?
To be clearer, I will give an example, of what I am thinking:
@autoreleasepool {
MyObject *obj = [[MyObject alloc] init]; // no autorelease call here
/* use the object*/
//....
// in the end it should get deallocated because it's lifespan ends, right?
// so why do we need to call autorelease then?!
}
PS: Please don't tell me that because of ARC we don't need to do some things because ARC takes care of them. I am fully aware of that, but I want to leave ARC aside for just a few moments to understand the mechanism of memory management.