3 ms·
Most of the time, memory management with objc is easy; if you alloc, retain, copy or mutableCopy, you need to release (or autorelease). Combine that with Clang'
by Zev 17y ago
Most of the time, memory management with objc is easy; if you alloc, retain, copy or mutableCopy, you need to release (or autorelease). Combine that with Clang's Static Analyzer to give a warning on a leak, and you shouldn't have any problems with memory.
- weaksauce 17y agoGreat tip on the analyzer. Here is a link to the project: http://clang-analyzer.llvm.org/ http://clang-analyzer.llvm.org/
- Zev 17y agoThe analyzer comes built into Xcode 3.2 on 10.6; no need to install another version (unless you're still on 10.5, I suppose — but you should update to 10.6 in that case, if only for the new dev tools). Either hit cmd + shift + a to run the analyzer or check the box in the project info to automatically run it before every build.
- eob 17y agoAgreed: memory management is easy if you stop thinking about it as reference counting and instead follow exactly what Zev just said. When I first got into ObjC I kept getting hung up on this idea of a "reference count" until someone on #iphonedev beat it into my head that all you need to do is release the things you declared ownership over.
- DenisM 17y agohow about retain cycles?
- Zev 17y agoTo me, that would be a problem with your code, not Objective C or anything within the Cocoa frameworks. I would personally say that if an object is retaining its parent (or parent's parent, etc), there's something wrong with your design and you should step back to reconsider things. Matt Gallagher put it much better than I can and I would recommend reading his post on it: http://cocoawithlove.com/2009/07/rules-to-avoid-retain-cycles.html http://cocoawithlove.com/2009/07/rules-to-avoid-retain-cycle...
- DenisM 17y agoAnd you call that kind of memory management "easy"? Looks quite contrived to me.