The Objective-C 2.0 introduced a garbage collector. It is nice and very simple to use.
However, I still prefer old style, release, retain, copy model. The reason is simple. You can control when to retain and release object. By doing so, you can manage memory more well. I don’t think old style is difficult to understand.
However, when you are involved in a group project in which a few programmers join, you don’t know how others write memory related codes. In such a case, garbage collection can be better.
Anyway, when making threads, you are supposed to make a dedicated memory pool for yourself. In the end of such thread function, you should issue :
However, it can raises BAD_ACCESS_EXE exception. Why? It is because certain objects are released too much. Especially when you deal with collections, this can happen, because Apple’s explanation when objects are retained, just referenced, or copied is not clear sometimes.
How to figure out which causes the exception and where it happens?
There are good documentation on the issue.
- Instruments on Leopard: How to debug those random crashes in your Cocoa app
- CocoaDev Debugging Autorelease