release/autorelease confusion in cocoa for iphone

前端 未结 6 1559
迷失自我
迷失自我 2020-12-15 01:48

I\'m slowly teaching myself cocoa for the iPhone(through the Stanford Class on iTunes U) and I\'ve just gone through the part on memory management, and I wanted to hopefully

6条回答
  •  囚心锁ツ
    2020-12-15 02:08

    The rule is simple: if you alloc, copy or retain, it's your responsibility to release. If you didn't, it's not. However, if you need to rely on an object staying around, you have to retain (and subsequently release).

    We can treat the string literal according to the rules - you don't need to release it because you don't own it. That's simple; there's no need to worry about whether they're special cases or not, just follow the rules and you'll be fine.

    I wrote up a blog post with a collection of articles about the Cocoa memory management rules; I'd recommend following up some of the references.

提交回复
热议问题