• 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
Listener related crashing bug releasing subviews of a custom view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Listener related crashing bug releasing subviews of a custom view


  • Subject: Listener related crashing bug releasing subviews of a custom view
  • From: Ken Tozier <email@hidden>
  • Date: Fri, 22 Feb 2008 10:22:27 -0500

Hi

I have a custom view which contains a number of other custom subviews and am getting the following crashing bug when trying to release it in the view's "dealloc" method

"An instance 0x152f8750 of class PMPageMasterField is being deallocated while key value observers are still registered with it. Break on _NSKVODeallocateLog to start debugging."

How do I follow the error message suggestion and "Break on _NSKVODeallocateLog to start debugging"?

Here are the subview initialization methods
- (void) initUserFields
{
NSRect selfFrame = [self frame],
pageFrame = NSMakeRect(0, selfFrame.size.height - PAGE_FIELD_HEIGHT - 1, selfFrame.size.width, PAGE_FIELD_HEIGHT),
masterFrame = NSMakeRect(0, pageFrame.origin.y - NAME_CODE_FIELD_HEIGHT, selfFrame.size.width, NAME_CODE_FIELD_HEIGHT);

pageField = [[PMPageNumberField alloc] initWithFrame: tempFrame model: model];
masterField = [[PMPageMasterField alloc] initWithFrame: tempFrame model: model];

[self addSubview: pageField];
[self addSubview: masterField];
}


Here's the dealloc method for the view containing "masterField" and "pageField"
- (void) dealloc
{
// tried both of the following removeFromSuperview/release
// individually and in combination but get the crash no matter what I try
[pageField removeFromSuperview];
[masterField removeFromSuperview];

[pageField release];
[masterField release];

[super dealloc];
}


Here's the init method for "masterField" and "pageField" (they're basically identical except for the model)
- (id) initWithFrame:(NSRect) inFrame
model:(PMPageModel *) inModel
{
self = [super initWithFrame: inFrame];
if (self)
{
NSString *tempMaster = [[inModel master] nameCode] ;

model = inModel;

// set action handler and target
[self setAction: @selector(handleTextEntry)];
[self setTarget: self];

// set formatter and properties
[self setAlignment: NSCenterTextAlignment];
[self setFont: [PMFonts iconViewFont]];
[self disableEditing];

// init the page number
[self setStringValue: tempMaster];
[self setPageCode: tempMaster];

// add model observer
[self addModelObserver];
}

return self;
}


Here's the dealloc for the subviews
- (void) dealloc
{
	NSLog(@"Entered: %@:dealloc", NSStringFromClass([self class]));
	[self removeModelObserver];

	[super dealloc];
}

Here's the addModelObserver method
- (void) addModelObserver
{
	[model addObserver: self
			forKeyPath: @"master"
			options: NSKeyValueObservingOptionNew
			context: NULL];
}

And here's the removeModelObserver method
- (void) removeModelObserver
{
	// Next line is where it crashes
	[model removeObserver: self
			forKeyPath: @"master"];
}

The model does not register listeners with the view, it's strictly one way, so I don't understand why it crashes on "[model removeObserver: self forKeyPath: @"master"]"

I've combed through the code checking every "addObserver:forKeyPath:options:context:" call very carefully and can't find any classes that register as observers for the subviews in question, so have no clue what is listening or why I'm getting this message. Could the KVO mechanism be registering listeners behind my back? And if so, how do I prevent that unwelcome listener registration from happening?

Any help appreciated

Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Listener related crashing bug releasing subviews of a custom view
      • From: Martin <email@hidden>
  • Prev by Date: static library (.a) is not of required archutecture
  • Next by Date: Re: Embedded Framework stripping
  • Previous by thread: Re: static library (.a) is not of required archutecture
  • Next by thread: Re: Listener related crashing bug releasing subviews of a custom view
  • Index(es):
    • Date
    • Thread