Re: NSDocument and dealloc
Re: NSDocument and dealloc
- Subject: Re: NSDocument and dealloc
- From: Fredrik Olsson <email@hidden>
- Date: Tue, 13 Jun 2006 17:13:31 +0200
Pierre Bernard skrev:
Do you use bindings?
I found that binding to the document (e.g. to "managedObjectContext") will retain the document. My solution is to break such bindings in [NSDocument close].
No bindings but maybe a strange configuration. The application is split
into three targets:
GMT-X Shared, a framework that defines the basic MTGMTXDocument that is
the base class for building plug-ins. A plug-in is a document type.
GMT-X, the main application, linked against GMT-X Shared and scans it's
PlugIn folder for bundles with plug-ins.
MTFiletransferDocument, a bundle with the MTFiletransferDocument class
as the principal class, that is a subclass of MTGMTXDocument, that
naturaly links against the framework as well. This bundle has a nib,
with the UI for the document window. It is when loading this nib, after
having closed another window that is crashes.
// Fredrik Olsson
Pierre
On Tuesday, June 13, 2006, at 03:21PM, Fredrik Olsson <email@hidden> wrote:
It does not seem like dealloc is called for my NSDocument instances, at
least no NSLog responses or hooking up on any breakpoints. I find this
quite strange, or is there something I do terribly wrong when creating
new instances of of my NSDocumnet subclasses:
MTGMTXDocument *doc = [[plugInClass alloc] initWithDatapacketRow:nil
dataPath:@"/tmp"];
if (doc) {
[[NSDocumentController sharedDocumentController] addDocument:doc];
[doc makeWindowControllers];
[doc showWindows];
}
And then the standard plugin class (A subclass of NSDocument) implements
this imple method:
- (id)initWithDatapacketRow:(MTXMLNode *)datapacketRow
dataPath:(NSString *)dataPath
{
self = [super init];
if (self) {
if (datapacketRow) {
_isNew = NO;
_datapacketRow = [datapacketRow retain];
} else {
_isNew = YES;
_datapacketRow = [[MTGMTXDocument defaultDatapacketRow] retain];
[_datapacketRow setAttribute:[[self class] contentName]
withName:@"Type"];
}
_dataPath = [dataPath retain];
}
return self;
}
I can not see any trouble here.
The symptoms of my problem is that if I do this:
1. Open a document.
2. Close it.
3. Open a new document.
Then I will get a NSCFArray: "attempt to insert nil" when callong
showWindows
If the following trace could help anyone, help me, I would be happy :):
#0 0x9294d008 in -[NSException raise]
#1 0x9294ce5c in +[NSException raise:format:]
#2 0x9290fd4c in -[NSCFArray addObject:]
#3 0x936f4bb8 in -[NSIBObjectData
nibInstantiateWithOwner:topLevelObjects:]
#4 0x936e103c in loadNib
#5 0x936e0a94 in +[NSBundle(NSNibLoading)
_loadNibFile:nameTable:withZone:ownerBundle:]
#6 0x93737f64 in +[NSBundle(NSNibLoading)
loadNibFile:externalNameTable:withZone:]
#7 0x937cb930 in -[NSWindowController loadWindow]
#8 0x937cb654 in -[NSWindowController window]
#9 0x937cb564 in -[NSWindowController showWindow:]
#10 0x937d8ac8 in -[NSDocument showWindows]
I can also do this to get another error:
1. Open a document.
2. Open a document.
3. Close any of the two.
4. Close the remaining one.
In fact it does not matter how many documents I open, it will always
fail on the second close. This time with a EXC_BAD_ACCESS, This is the
trace:
#0 0xfffeff20 in objc_msgSend_rtp
#1 0x9290e968 in NSPopAutoreleasePool
#2 0x936d70d4 in -[NSApplication run]
#3 0x937c7bfc in NSApplicationMain
#4 0x00078fac in main at main.m:13
So I guess I release something one time too many... :/.
I have spend the day stepping and balancing retain/release, and can not
find anything fishy.
So I am asking if there is something obvious I have done. Or how I can
find the sneaky release...
MallocDebug and ObjectAlloc have not helped me much, in all honest I
have no clue how to use them :)
// Fredrik Olsson
_______________________________________________
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
---
Spinning WebObjects or cooking up Cocoa in Switzerland?
Let me know: http://homepage.mac.com/I_love_my/
_______________________________________________
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