I'm having a hard time tracking down a crash related
[removeObserver:forKeyPath:]. Unfortunately the bug is not
reproducable, I've only seen various crash logs looking like this one:
Since I've been hunting down this bug for quite some time now without
success, maybe someone on this list can have a look at the code and
point me to what I'm doing wrong.
I have a tree controller class, which manages an outline view
consisting of simple items and groups of those items. My tree
controller class also manages an NSArrayController, which is used to
bind various user interface elements to. The content array of this
array controller contains all simple items, but not the groups. The
tree controller class observers the 'title' attribute of the simple
items, so it can reload the outline view when the user changes an
item's title.
My first thought was that the item which is going to get its observer
removed has already been released and therefore is invalid at the
point removeObserver:forKeyPath: is invoked. But the item is unbound
before it is getting removed from the the tree hierarchy and the
allItems array. So the retain count should be 2 at the crash time.
Thanks for any hints or tips,
Ilja
Here is that code that is supposed to cause the crash according to
the crash log:
while (nil != (itemToRemove = [itemEnum nextObject]))
{
GSTreeItemGroup *parent;
parent = [self parentGroupForItem:itemToRemove];
NSAssert (parent, @"couldn't get parent for item");
if ([itemToRemove isKindOfClass:[GSTreeItemGroup class]]) //
if its a group, manually unbind leaf items and remove them from the
allItems array afterwards
{
NSArray *subitems = [itemToRemove
allPlainItemsDeep];
NSEnumerator *e = [subitems objectEnumerator];
id theSubitem;
while (nil != (theSubitem = [e nextObject]))
{
[self removeBindingsForItem:theSubitem];
}
[allItems removeObjectsInArray:subitems]; // remove from
array controllers content array
}
else // is a simple item
{
[self removeBindingsForItem:itemToRemove]; // has to be
invoked before [parent removeItem:]
[allItems removeObject:itemToRemove]; // remove from
array controllers content array
}
[parent removeItem:itemToRemove];
}
[outlineView reloadData];
[self synchronizeArrayControllerSelection];
}
_______________________________________________
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