when is it safe to release an NSThread?

后端 未结 1 1998
闹比i
闹比i 2021-01-06 10:39

Below is the runloop for my secondary NSThread* processThread

To close the thread I call

//cancel secondary thread
[processThread cancel]
//signal co         


        
相关标签:
1条回答
  • 2021-01-06 10:58

    Yes, it is safe to call release against an NSThread if you are done with it. In non-GC Objective C code the idiom is that once you are done accessing an object you may release it. If anything else needs that object, including the object itself it their job to have a retain against it. In general if an object cannot be safely disposed at arbitrary times it will retain itself while it is in an unsafe state, and release itself when it can be safely disposed of.

    This is how things like NSThread and NSURLConnection work (NSURLConnection actually retains its delegate and does a lot of fancy stuff to cope with the retain loop that occurs.

    0 讨论(0)
提交回复
热议问题