KVO/dealloc problems
KVO/dealloc problems
- Subject: KVO/dealloc problems
- From: Duncan Campbell <email@hidden>
- Date: Mon, 24 Apr 2006 16:36:23 +1000
Hi list,
I'm having some problems removing a KVO. I'm creating an object, and
adding it as an observer like so (this is the parent class i want to
observe):
- (id)init
{
if (self = [super init])
{
_obj = [[MyObject alloc] init];
[self addObserver:_obj forKeyPath:@"somevalue"
options:NSKeyValueObservingOptionNew context:NULL];
}
return self;
}
and in my dealloc:
- (void)dealloc
{
[self removeObserver:_obj forKeyPath:@"somevalue"];
[_obj release];
_obj = nil;
[super dealloc];
}
and obviously, i have implemented - (void)
observeValueForKeyPath:ofObject:change:context: in the "MyObject" class.
My problem is that when the dealloc above happens, I get an error:
"An instance 0x36e7a0 of class <SomeClass> is being deallocated while
key value observers are still registered with it."
so it would seem that I need to remove the observer before dealloc is
called.
Can anyone suggest where in fact i should be removing the observer?
(Note that the "MyObject" object does not know anything about the
parent class - so i cannot do the add/remove observer stuff there).
Cheers for any help.
D.
_______________________________________________
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