I gather that if I create an autoreleased object and I pass it to another thread to be worked on, this is bad if the first NSThread should happened to clean out its autorelease pool, or be killed. However if I want to avoid autoreleasing as a rule, what are some examples of where I cannot autorelease objects, particularly objects that I might want to share between NSThreads? It seems to me that most autoreleasing can be avoided.
Asked
Active
Viewed 39 times
0
-
You would probably have better luck using ARC and GCD – Jason Coco Oct 26 '13 at 22:34
-
ARC? It's a good technology but using it feels like wearing a bib. As for GCD I don't want to use too much Apple-specific stuff as my code must also run on Android (native C++). – user2923996 Oct 26 '13 at 22:37
-
Well, I disagree about ARC since it's letting the compiler do what the compiler does best. Totally understand about the x-plat stuff though. – Jason Coco Oct 26 '13 at 23:16
-
I can't see any reason you "cannot autorelease objects" – Bryan Chen Oct 28 '13 at 21:52
1 Answers
0
Just follow the memory management rules. Threads make no difference. A function only has to worry about what it does locally; it never has to worry about what any other function does. A function needs to retain an object if it needs to be assigned to an instance variable or something like that. When something is retained, it needs to be balanced with a release.

newacct
- 119,665
- 29
- 163
- 224