1、既然设置了ARC,为什么还需要@autoreleasepool,有什么好处?
池子做的是运行时延迟释放,ARC已经在编译时解决了手动管理的问题,那么就没必要使用@autoreleasepool,还占内存。
2、ARC频繁释放内存 和@autoreleasepool一起释放 感觉还是前者 要好些,
这不是像数据连接池一样可以共享资源。只是延迟释放内存(又不能共享内存)。
按着这个推论在ARC条件下,没必要使用@autoreleasepool。
我知道这种想法有问题,但是不知道是哪里,新手问题多,莫喷
ARC does not abandon the
@autoreleasepool
,而是在编译阶段帮你插入必要的retain
/release
/autorelease
code calls.So, unlike what you think, ARC is still delayed release and still relies on
NSAutoreleasePool
. It is essentially the same as manually calling those functions in non-ARC mode, except that the compiler will ensure reference counting. correctness.Reference:
Using @autoreleasepool is useful.
Under normal circumstances, the variables you create will be released when they exceed their scope.
And if your function is very long and many intermediate variables appear during the running of your function, occupying a large amount of memory, what should you do?
Using @autoreleasepool.
The variables created in @autoreleasepool will be released once when @autoreleasepool ends. In fact, @autoreleasepool is equivalent to a layer of scope.