1

There are many articles talk about optimizations of memory management in ARC, one optimization is fast autorelease, I have asked a question about this, Matt Galloway also has a famous article talks about it.

Fast autorelease says if caller and callee are both under ARC, the returned object of callee needn't be add into autorelease pool.

So my question is if all my source code is compiled under ARC, can I get ride of autorelease pool?

If so, does it means if someday apple mandates us use ARC, autorelease pool will be useless.

If not, can you tell some cases that autorelease pool is still used under this condition.

You will know that it's not duplicate if you read my question and comments below carefully.

Community
  • 1
  • 1
KudoCC
  • 6,912
  • 1
  • 24
  • 53
  • @dasblinkenlight I have seen that question before I asked this question. My goal is to know if there are cases that autorelease pool is still used when all the code are compiled under arc, that question doesn't answer it. – KudoCC Oct 26 '16 at 03:20
  • that question does answer it, that code is compiled under ARC and it shows why the autorelease pool is useful... autorelease pools arent specific to MRC. its probably very rare that you will need your own autorelease pool, so probably shouldnt worry about it, even that example is somewhat unrealistic (but could happen) – Fonix Oct 26 '16 at 03:26
  • also there is a [down voted answer](http://stackoverflow.com/a/22000483/1219956) on that question, its actually quite useful because it shows how autorelease pools can be mistaken as not useful, it shows the subtle difference when it should be used and not used – Fonix Oct 26 '16 at 03:29
  • @Fonix We don't know if `NSNumber` is compile with ARC or MRC then, but I have tried this on iOS10, dealloc get called immediately after printing the object address. `+ (Testing *) testing { return [Testing new];} + (void) test { while(true) NSLog(@"p = %p", [self testing]);}`, this code is related to the down voted answer. – KudoCC Oct 26 '16 at 04:33
  • hmm maybe clang has changed its behaviour then, interesting, might be clever enough to detect this situation – Fonix Oct 26 '16 at 04:44
  • 2
    @Fonix You can check the [answer](http://stackoverflow.com/a/29252564/1079899) to my another question I mentioned above, it is called fast autorelease. – KudoCC Oct 26 '16 at 04:48
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/126687/discussion-between-fonix-and-kudocc). – Fonix Oct 26 '16 at 05:00

0 Answers0