release/autorelease confusion in cocoa for iphone

前端 未结 6 1584
迷失自我
迷失自我 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:03

    Last part first: You will indeed have to auto/release Me. However, you will also have to add [firstName release]; and [lastName release]; in -dealloc; or better yet; self.firstName = nil;

    As for string literals; this part gets a bit hairy, but [@"String literal" release] is essentially a noop. As such, there is a difference between the two temp objects, but as you won't generally know which one you'll be dealing with, adding [temp release]; is generally the safe choice, unless you know it'll contain an autoreleased object.

提交回复
热议问题