• 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
Re: Crash after [NSData dataWithData:(NSMutableData *)]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Crash after [NSData dataWithData:(NSMutableData *)]


  • Subject: Re: Crash after [NSData dataWithData:(NSMutableData *)]
  • From: Charilaos Skiadas <email@hidden>
  • Date: Tue, 26 Jul 2005 19:34:56 -0500

On Jul 26, 2005, at 6:07 PM, email@hidden wrote:

On Jul 26, 2005, at 6:48 AM, j o a r wrote:

This is Cocoa memory management 101...


A precise description of my Cocoa experience! :-)

Then you should read the following immediately, if you haven't yet: http://www.stepwise.com/Articles/Technical/2001-03-11.01.html http://www.stepwise.com/Articles/Technical/HoldMe.html

On Jul 26, 2005, at 6:52 AM, Nicko van Someren wrote:

You did not get the sourceData object with new, alloc or copy, therefore you do not "own" the object and you should not release it since it is an autorelease object.


Ah, that's the problem -- I was under the incorrect impression that the <thing>With<Condition> methods behaved like [[Thing alloc] initWith<Condition>].


So, if I had done [[NSData alloc] initWithData:...] instead of [NSData dataWithData:...], the result it would not be autoreleased and would have a retain count of 1. Did I get that right?

Almost. Its retain count might be even bigger for various reasons that do not concern you. As far as you (your method) is concerned, you are responsible for releasing (or autoreleasing) this object exactly once. Don't get too tangled up in the retain count issue, it might be affected by framework-internal operations that you have no control over. Just make sure you balance any new/init/copy/retain with a release/autorelease, unless of course you want to keep the object around for longer.


Thanks again.

Haris


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Crash after [NSData dataWithData:(NSMutableData *)] (From: email@hidden)
 >Re: Crash after [NSData dataWithData:(NSMutableData *)] (From: Nicko van Someren <email@hidden>)
 >Re: Crash after [NSData dataWithData:(NSMutableData *)] (From: email@hidden)

  • Prev by Date: Re: Cocoa and cooperative threads
  • Next by Date: Re: Custom line breaking in NSTextView
  • Previous by thread: Re: Crash after [NSData dataWithData:(NSMutableData *)]
  • Next by thread: Re: Cocoa-dev Digest, Vol 2, Issue 1149
  • Index(es):
    • Date
    • Thread