3
votes

I am posting here after reading some similar threads, but you know each issue still has his own specific problem, that's why I still need your help.

My app crashes with this stack trace:

[ReviewVC respondsToSelector:]: message sent to deallocated instance

I tracked that on instruments trying to see the relevant code causing the crash: enter image description hereenter image description hereenter image description here

here is the relevant code for ReviewVC in the didSelectRowAtIndexPath: delegate method:

self.reviewVC = [[[ReviewVC alloc] initWithNibName:@"Review"
                                                     bundle:nil] autorelease];
[viewControllerArray addObject:self.reviewVC];
self.appDelegate.splitViewController.delegate = self.reviewVC;

reviewVC is an instance variable and a property, here is it's property declaration:

@property (nonatomic, retain)  ReviewVC *reviewVC;

Am I missing something ?

1
Do you have a @synthesize? What if you omitted the autorelease? - ott--
yes it's @synthesize'd - Malloc
Does self.reviewVC ever get set? Set a breakpoint and see what your ReviewVC alloc returns. Maybe try and retrieve it using [NSBundle mainBundle] loadNibNamed:] instead. - Tim
I tried to remove the autorelease command and all work fine now, still need some explanation about that if possible :) - Malloc
What is the purpose of viewControllerArray? You're adding reviewVC and then what? The runtime may have detected that you're not using anymore (assigning the delegate doesn't count). I assume that the reviewVC was gone after that method. - ott--

1 Answers

0
votes

Have look at this. It seems maybe viewControllerArray is being released and with it the instance ReviewVC added to it. I think the autorelease is fine but check how viewControllerArray is retained.

NSObject obj1;
obj1=[[NSObject alloc] init];
//obj1's retain count is 1 here.

[array1 addobject:obj1];
//obj1's retain count incremented by 1, so the total retain count is 2.

[obj1 release];
//obj1's retain count decremented by 1, so the total retain count is 1.