views:

49

answers:

2

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?

+3  A: 

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

Benjamin Ortuzar
..Analize in XCode. What does that do to your code..? ;)
leson
Thank you, just wanted to check, coming to Objective-C only recently its taken a while (and a few reads of the memory management docs) to get to grips with how things work ... much appreciated.
fuzzygoat
+3  A: 

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.

Noah Witherspoon
Thank you Noah.
fuzzygoat