[warning, newbie] a new, saved, opened and closed again window causes app to crash (EXC_BAD_ACCESS)
[warning, newbie] a new, saved, opened and closed again window causes app to crash (EXC_BAD_ACCESS)
- Subject: [warning, newbie] a new, saved, opened and closed again window causes app to crash (EXC_BAD_ACCESS)
- From: Charilaos Skiadas <email@hidden>
- Date: Sat, 12 Mar 2005 19:01:47 -0600
Sorry, I keep forgetting to press "reply all" instead of "reply".
Begin forwarded message:
From: Charilaos Skiadas <email@hidden>
Date: March 12, 2005 7:00:30 PM CST
To: OS <email@hidden>
Subject: Re: [warning, newbie] a new, saved, opened and closed again
window causes app to crash (EXC_BAD_ACCESS)
On Mar 12, 2005, at 6:13 PM, OS wrote:
- (id)init
{
self = [super init];
if (self) {
model = [[Model alloc] init];
}
return self;
}
- (void)dealloc
{
[model release];
[super dealloc];
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
model = [NSKeyedUnarchiver unarchiveObjectWithData:data];
return YES;
}
I would expect that unarchiveObjectWithData returns an autoreleased
object, so you don't own it and when you try to release it you will
crash. Try using:
model = [[NSKeyedUnarchiver unarchiveObjectWithData:data] retain];
instead.
Always remember, only alloc, copy and retain give you an object that
you are responsible for. All other methods are supposed to be
returning autoreleased objects.
// save document
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
return [NSKeyedArchiver archivedDataWithRootObject:model];
}
I think 'model = [NSKeyedUnarchiver unarchiveObjectWithData:data];'
is the source of the problem, am I right or is this the correct
method to unarchive the 'model' object?
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