开发者

Memory management / ownership question?

Do I have this right ...

// Reactor.h
@property(nonatomic, retain) NSMutableArray *reactorCore;

// Reactor.m
[self setReactorCore:[NSKeyedUnarchiver unarchiveObjectWithFile:[self dataFilePath]]];开发者_如何学运维
...

-(void)dealloc {
    [reactorCore release];
    [super dealloc];
}

I am pretty sure I am doing this right (but just wanted to check). By my way of thinking NSKeyedUnarchiver returns an object it owns, I am then taking ownership via the @property, later I release reactorCore and all is good?


I believe your code is corect. When in doubt you could use Build and Analize in XCode to check for possible leaks.


That's right. The NSKeyedUnarchiver method—since it doesn't contain the words copy, new, or anything like that—will return an autoreleased object, which you need to retain (as you are doing) to keep ownership of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜