initWithCoder / unarchiveObjectWithData Memory Management Question
initWithCoder / unarchiveObjectWithData Memory Management Question
- Subject: initWithCoder / unarchiveObjectWithData Memory Management Question
- From: Thomas Wetmore <email@hidden>
- Date: Sat, 20 Feb 2010 01:47:27 -0500
I have a memory management question involving the interaction of:
- (id) initWithCoder: (NSCoder*) coder
from any class that implements <NSCoding> and
+ (id) unarchiveObjectWithData: (NSData*) data
from the NSKeyedUnarchiver (or any unarchiver) class.
After the following lines of code run ...
NSData* data = [NSData dataWithContentsOfFile: myObjectPath];
myObject = [NSKeyedUnarchiver unarchiveObjectWithData: data];
(error handling removed), has myObject been retained, or must I now retain it. The unarchiveObjectWithData class method causes myObject's class's initWithCoder object method to run. I assume that initWithCoder obeys memory management rules and returns a newly alloc'ed and retained object. Does the unarchiveObjectWithData method return that retained object unaltered, or does it autorelease it first, so that the unarchiveObjectWithData method obeys the usual convention of class factory methods to return autoreleased objects?
I apologize for asking this seemingly basic question, but I can't find the answer in the Apple docs or via googling, and there seems to me to be a clash of well-established conventions involved. The question came up because I found a case in my code where I convinced myself I was over-releasing an object created in this fashion, but the application never fails because of it.
Thanks,
Tom Wetmore, Chief Bottle Washer, DeadEnds Software
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden