Re: Crash after [NSData dataWithData:(NSMutableData *)]
Re: Crash after [NSData dataWithData:(NSMutableData *)]
- Subject: Re: Crash after [NSData dataWithData:(NSMutableData *)]
- From: Nicko van Someren <email@hidden>
- Date: Tue, 26 Jul 2005 14:52:56 +0100
On 26 Jul 2005, at 14:35, email@hidden wrote:
Omitting a great deal of intervening code for brevity, my program
is doing this:
NSMutableData * sourceData = [NSMutableData dataWithCapacity:
[theAnnotatedData length]];
// append some bytes to sourceData
NSData * destinationData = [NSData dataWithData:aData];
[sourceData release];
The program crashes with EXC_BAD_ACCESS in NSPopAutoreleasePool/
objc_msgSend_rtp if I release sourceData. If I comment out the last
line, no crash.
There is plenty of other stuff I could be doing wrong (e.g., being
a hopeless noob), but as a sanity check, am I supposed to be
retaining something or not using NSData dataWithData: from an
instance of NSMutableData?
This is a classic object ownership question. 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. Note that you should probably be retaining the
destinationData because it too is autoreleased and will disappear
under your feet if you're not careful.
Nicko
_______________________________________________
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