• 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
Re: NSDocument and dealloc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDocument and dealloc


  • Subject: Re: NSDocument and dealloc
  • From: Fredrik Olsson <email@hidden>
  • Date: Tue, 13 Jun 2006 16:26:25 +0200

Fredrik Olsson skrev:
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:

Ok, I have figured this one out at least.
MTGMTXDocument *doc = [[plugInClass alloc] initWithDatapacketRow:nil dataPath:@"/tmp"];
if (doc) {
[[NSDocumentController sharedDocumentController] addDocument:doc];
[doc makeWindowControllers];
[doc showWindows];
[doc release];
}

But it is not enough to solve why it crashes/leaves a nil somewhere, after closing a window.
I have stripped down the app to pretty much nothing but opening an empty doc with a placeholder textfield on... and still something is not right :/


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

_______________________________________________ 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
References: 
 >NSDocument and dealloc (From: Fredrik Olsson <email@hidden>)

  • Prev by Date: Re: Launch another app without losing focus
  • Next by Date: Re: IB: Maintaining bindings when copying controls
  • Previous by thread: NSDocument and dealloc
  • Next by thread: Re: NSDocument and dealloc
  • Index(es):
    • Date
    • Thread