Does every thread need its own autorelease pool?

后端 未结 3 541
南旧
南旧 2020-12-17 04:46

Does every thread have to have its own pool? I am writing an iPhone app which uses threads. If I do not put a pool on a thread it complains abut leaking.

What I wan

3条回答
  •  有刺的猬
    2020-12-17 05:38

    To precise a little bit what JustSid said : When autorelease is called on an object, the autoreleasepool associated with the current thread is used. So if no autoreleasepool is associated with your thread, the autorelease will not work, leading to memory leak.

    The final answer being : If your thread creates object(s) and count on the autorelease mechanism to release them, then you need to create an autoreleasepool for that thread !

提交回复
热议问题