views:

78

answers:

1

Hello,

I've been struggling with this for last few days and I cannot find any solution, so I ask you for advice.

I have two UIViewControllers: NewPostUIViewController and SettingsUIViewController. In the second one I have a field:

id<SettingsUIViewControllerDelegate> delegate

and the first one implements protocol

SettingsUIViewControllerDelegate

When a button is pressed the following code is executed in NewPostUIViewController:

SettingsUIViewController *settingsUIViewController  = [[SettingsUIViewController alloc] initWithNibName:@"SettingsView" bundle:nil]; 
settingsUIViewController.title = NSLocalizedString(@"Settings", @"Settings view title");
settingsUIViewController.delegate = self; 
[self presentModalViewController:settingsUIViewController animated:YES];
[settingsUIViewController release];

when I want to dismiss SettingsUIViewController I call (code in SettingsUIViewController):

[delegate settingsAreDone:sender];

and settingsAreDone looks following (code in NewPostUIViewController):

    [self dismissModalViewControllerAnimated:YES];

This all concludes in:

[CALayer release]: message sent to deallocated instance 0x5a76840

I tried to debug the code by setting a breakpoint in the release methods of both view controllers, but these methods are called so often that it's hard to say what can be the cause of this problem.

Any ideas?

A: 

First, the error you're getting isn't indicating that -release is being sent to a view controller, so breakpoints in your view controllers won't help. The over-release is happening on a CALayer, which is likely part of the modal animation.

First, we start with some basics about the delegate. I don't feel great about this being the cause, but you should always start with the easy basics. Your SettingsUIViewController delegate property should be assign, not retain, so you avoid retain loops. That's probably correct already, but when it's not, you can wind up with cases where objects exist longer than you expect them to (and so can send messages after their targets have gone away). Again, probably not the issue, but easy to check and easy to fix.

Next, you should look at the stack trace at the crash. Who is calling [CALayer release]? A possible cause is that the owning view controller gets released before the animation stops. When you close the settings controller, do you immediately close the NewPost controller?

Rob Napier
Thanks for the comment and sorry for late response. To answer your suggestions: yes delegate is a retain property.
Jakub
Here is how the stack trace looks like: http://img375.imageshack.us/img375/6251/asmforwarding0x0267ad50.png And no I don't close NewPost controller, this is the main view controller of my app.
Jakub