Using Autorelease Pools

There are, however, three occasions when you might use your own autorelease pools:

1.  If you are writing a program that is not based on a UI framework, such as a command-line tool.

2. If you write a loop that creats many temporary objects.

3.  you spawn a secondary thread.  

(2) Autorelease Pools and Threads

Each thread in a Cocoa application maintains its own stack of NSAutoreleasePool objects. When a thread terminates, it automatically releases all of the autorelease pools associated with itself.

 

(3) ownership

 * If you create an object, you own it.

 * If you get an object from somewhere else, you do not own it. if you want to prevent it being disposed of, you must add yourself as an owner.

 * If you are an owner of an object, you must relinquish ownership when you have finished using it.

原文地址:https://www.cnblogs.com/JiesonWu/p/2593488.html