Your code is correct; no memory leak.
theData = [NSData dataWithContentsOfFile:inFile];
equivalently
theData = [[[NSData alloc] initWithContentsOfFile:inFile] autorelease];
At this point, Data has a reference count of 1 (if less, it will be freed). The reference counter will automatically decrease at some point in the future by the pool of autoresists.
decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:theData];
The decoder object stores a link to Data, which increments the reference count to 2.
After the method returns, the resource pool will reduce this value to 1. If you release Data at the end of this method, the reference counter will become 0, the object will be freed, and your application will crash when you try to use it.
source
share