• 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
KVO/dealloc problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: KVO/dealloc problems
      • From: "Jeremy Higgs" <email@hidden>
  • Prev by Date: Re: .Mac support to C/C++ application
  • Next by Date: Re: .Mac support to C/C++ application
  • Previous by thread: Re: .Mac support to C/C++ application
  • Next by thread: Re: KVO/dealloc problems
  • Index(es):
    • Date
    • Thread