Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MyDocument instance variables, dealloc problems



I've run into some frustrating and confusing problems related to memory management. I have an NSDocument subclass (MyDocument) with several instance variables. One of those instance variables is an NSDictionary called possibleColumns. The setter for possibleColumns is dead simple:

(void) setPossibleColumns: (NSDictionary *) value
{
	possibleColumns = value;
	[possibleColumns retain];
}

If I set that instance variable at all, I run into a big problem. The first document created by my app upon opening works fine. However, if I open another document, it's instance variables seem to be completely messed up. Specifically, one of the instance variables, myWindow, is an IBOutlet set in the nib file to point to the window for the document. Somehow, the instance docWindow ends up pointing to (seemingly) random other objects in the second (and third, etc) document created in my app. This creates serious problems including hard crashes for obvious reasons when the program tries to do things to/with to docWindow. This odd behavior goes away if I never set possibleColumns. Any idea why this might be?

Further confusing matters, MyDocument's dealloc method doesn't get called when a document window is closed. However, if I remove the retain message in the setPossibleColumns: method, then MyDocument's dealloc method does get called. Of course, I need to retain possibleDocuments otherwise it ends up getting released out from under MyDocument when I need it. Why should the presence or absence of [possibleColumns retain]; in that setter method (and that's the only line I'm changing in the whole project) change whether or not dealloc gets called on MyDocument? Removing the retain message also causes the problems with instance variables in later documents being corrupt to disappear, but again, if I don't retain possibleColumns I get crashes related to accessing a released object.

I'm really at a loss for further things to try here.  Any thoughts?

Thanks,
Andrew
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.