• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
initWithCoder / unarchiveObjectWithData Memory Management Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: initWithCoder / unarchiveObjectWithData Memory Management Question
      • From: Uli Kusterer <email@hidden>
    • Re: initWithCoder / unarchiveObjectWithData Memory Management Question
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Removing item from CollectionView by drag it out.
  • Next by Date: Re: initWithCoder / unarchiveObjectWithData Memory Management Question
  • Previous by thread: Re: Removing item from CollectionView by drag it out.
  • Next by thread: Re: initWithCoder / unarchiveObjectWithData Memory Management Question
  • Index(es):
    • Date
    • Thread