Re: MyDocument instance variables, dealloc problems
Re: MyDocument instance variables, dealloc problems
- Subject: Re: MyDocument instance variables, dealloc problems
- From: Mike Abdullah <email@hidden>
- Date: Sun, 12 Nov 2006 09:35:17 +0000
eek! That is a very bad accessor method :)
You are retaining the new value, but never releasing the old.
Instead, try something like:
- (void)setPossibleColumns:(NSDictionary *)value
{
if (value == possibleColumns)
return;
[possibleColumns release];
possibleColumns = [value retain];
}
I'm not sure if that'll entirely solve your problem, but it's a start!
Mike.
On 12 Nov 2006, at 06:28, Andrew Madsen wrote:
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:
40gmail.com
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