• 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
[warning, newbie] a new, saved, opened and closed again window causes app to crash (EXC_BAD_ACCESS)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[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: OS <email@hidden>
  • Date: Sun, 13 Mar 2005 01:13:39 +0100

I have an object (NSCoding compliant) instantiated in a document's class of a (obviously) document based app. This object contains all the data of (and it is) the model.

If I create a new doc, manipulate its data and save it, all's well. Now, if I open a saved doc, and close it again the app burns in flames, spitting a 'EXC_BAD_ACCESS', it seems (looking at the debugger) that when 'mydocument' is being deallocated something is out of scope, and the debugger stops on '[model release]' (see code below).

mydocument.h relevant code:

Model *model;

mydocument.m relevant code:

- (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;
}
// 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?

'Model' is inited an dealloced correctly I'd say:

- (id)init
{
    self = [super init];
    if (self) {
		[self setVFlag:[NSNumber numberWithBool:NO]];
		... (more code, it's all the same) ...
    }
    return self;
}

- (void)dealloc
{
	[self setVFlag:nil];
	... (more code) ...
	[super dealloc];
}

Here's the encoding/decoding part:

- (void)encodeWithCoder:(NSCoder *)coder
{
	[self setVFlag:[coder decodeObjectForKey:@"vFlag"]];
	... (more code) ...
}
- (id)initWithCoder:(NSCoder *)coder
{
	[super init];
	[coder encodeObject:[self vFlag] forKey:@"vFlag"];
	... (more code) ...
	return self;
}

Another thing that I observed in ObjecAlloc is that 'model' instance count behaves like this:

- New doc: 1 instance
- Save and close doc: 0 instances
- Open saved doc: 2 instances!!
- Same counting is repeated for every created, saved, closed and opened document (until i close one of them and it burns, BTW)


More info from ObjectAlloc:

Event: (#823466) ObjectReleasedEvent
Time Index: 132364782.008965
Category: XMTDocument
Pointer: 0x78273d0		Size: 96
Thread: 0x307		Extra Data: 0x1
Backtrace:
	NSRecordAllocationEvent
	NSDecrementExtraRefCountWasZero
	-[NSObject release]
	-[_NSBindingInfo dealloc]
	__CFArrayReleaseValues
	__CFArrayDeallocate
	CFRelease
	-[NSBinder _dealloc]
	-[NSBinder dealloc]
	NSPopAutoreleasePool
	-[NSApplication run]
	NSApplicationMain
	main()   main.m:13
	start
	start

I suppose this should nail it but I'm too new to this to get it :(

(Yes I'm using bindings)

thanks,
OS

_______________________________________________
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


  • Prev by Date: Can't launch carbon XEmacs
  • Next by Date: Only NSOperationCopy?
  • Previous by thread: Re: Can't launch carbon XEmacs
  • Next by thread: Re: [warning, newbie] a new, saved, opened and closed again window causes app to crash (EXC_BAD_ACCESS)
  • Index(es):
    • Date
    • Thread