views:

128

answers:

1

I have narrowed down this error (which crashes my app):

-[NSConcreteMutableData release]: message sent to deallocated instance 0x6eaed40

to the following code:

emailData = [kmlDoc dataUsingEncoding:NSUTF8StringEncoding];

But, I cannot figure out why this error is being caused? That line is just setting a very large string to an NSData object. I am releasing emailData in the dealloc method.

What is going wrong here?

+4  A: 

You need to take ownership of the object:

emailData = [[kmlDoc dataUsingEncoding:NSUTF8StringEncoding] retain];

Or using retain/copy properties:

self.emailData = [kmlDoc dataUsingEncoding:NSUTF8StringEncoding];

Remember that you explicitly have to take ownership for returned objects from methods that contain neither new, alloc, retain or copy in their name as they return autoreleased instances.

See the Memory Management Guide for more.

Georg Fritzsche
Thank you for clearing this up. I used self.emailData and it solved my issue.
Nic Hubbard