Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

[IPHONE] [CALayer retainCount]: message sent to deallocated instance

Hi,

I'm getting the '[CALayer retainCount]: message sent to deallocated instance' message when pushing a viewcontroller on the navigation controller.

I have a FoodDirectoryController , which displays a number of food groups , which when selected push another child FoodDirectoryController on the navigationcontroller with the foods in that group. I select a food group , select back , select another food group and then it crashes.

This is the selection code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if(self.currentGroup == -1)
{
NSInteger group = indexPath.row + rowOffset;

FoodEntryDirectory* controller = [ViewControllerFactory newFoodEntryDirectoryController]; //autoreleases
self.childFoodEntryDirectory = controller;
self.childFoodEntryDirectory.delegate = self.delegate;
self.childFoodEntryDirectory.currentGroup = group;
[self.navigationController pushViewController:self.childFoodEntryDirectory animated:YES];

}
else
{
//select a food
}


}


This is the malloc stack for the instance:

Call [2] [arg=48]: thread_a067ffa0 |0x1 | start | main | UIApplicationMain | -[UIApplication _run] | GSEventRun | GSEventRunModal | CFRunLoopRunInMode | CFRunLoopRunSpecific | PurpleEventTimerCallBack | SendEvent | _UIApplicationHandleEvent | -[UIApplication sendEvent:] | -[UIWindow sendEvent:] | -[UITableView touchesEnded:withEvent:] | -[UITableView(_UITableViewPrivate) _sendSelectionDidChange] | -[FoodEntryDirectory tableView:didSelectRowAtIndexPath:] | -[UINavigationController pushViewController:animated:] | -[UINavigationController pushViewController:transition:forceImmediate:] | -[UINavigationController _startTransition:fromViewController:toViewController:] | -[UIViewController(UIViewControllerContentScrollView) contentScrollView] | -[UIViewController view] | -[UIViewController loadView] | -[NSBundle(NSBundleAdditions) loadNibNamed:owner:options:] | -[UINib instantiateWithOptions:owner:loadingResourcesFromBundle:] | _decodeObject | _decodeObjectBinary | -[NSArray(NSArray) initWithCoder:] | -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] | _decodeObjectBinary | -[UIRuntimeConnection initWithCoder:] | _decodeObject | _decodeObjectBinary | -[UITableView initWithCoder:] | -[UIScrollView initWithCoder:] | -[UIView initWithCoder:] | UIViewCommonInitWithFrame | -[UIView _createLayerWithFrame:] | +[NSObject alloc] | +[NSObject allocWithZone:] | internal_classcreateInstance | internal_classcreateInstanceFromZone | calloc | malloc zonecalloc



Have been racking my brains for hours now. Help would be very appreciated!

Thanks

MacBook Pro 2.2, Mac OS X (10.4.11)

Posted on Aug 9, 2008 9:49 AM

Reply
5 replies

Mar 27, 2009 9:53 PM in response to pcrawfor

I can't say with certainty or not if this is your problem, but the conditions are similar to a problem I had recently which also related to viewController usage. My error was "retainCount sent to freed object" but I vaguely recall also seeing something pointing at CALayer too.

Anyway, my mistake was confusing "loadView" and "viewWillAppear". I was using viewWillAppear and when I switched to loadView, the mysterious retainCount error vanished. Apple support rep Rincewind was nice enough to clarify the usage:

-loadView is meant for developers that are programatically generating a view hierarchy. In -loadView you create a hierarchy and assign the root view to the view controller's view property.

-viewWillAppear is a notification that the view controller's view is about to be presented to the user.

[IPHONE] [CALayer retainCount]: message sent to deallocated instance

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.