0

In my view I have a button, which is hooked to this method:

-(IBAction)showStore:(id)sender
{
    storeSinglePlayer *ssp = [[storeSinglePlayer alloc] init];
    ssp.imageH = self.imageURLH;
    ssp.imageV = self.imageURLV;
    CATransition* transition = [CATransition animation];
    transition.duration = 0.5;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush; 
    transition.subtype = kCATransitionFromTop;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
    [self.navigationController pushViewController:ssp animated:NO];
 }

When I click this button, it shows me the 'store single player' view controller. Also the 'store single player' view controller has a back button which is hooked to the following method:

-(IBAction)didPressBack:(id)sender
{
    CATransition* transition = [CATransition animation];
    transition.duration = 0.5;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush; 
    transition.subtype = kCATransitionFromBottom;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
    [self.navigationController popViewControllerAnimated:NO];

}

Clicking the back button also does get me back to my previous view.

But now here is the weird problem. If I repeat this 10 times, i.e. Click the button to show 'storeSinglePlayer' and then click the back button on 'storeSinglePlayer', I get the error:

[storeSinglePlayer respondsToSelector:]: message sent to deallocated instance 0xe5f6160

And, this not just only on my multiple tries, it just randomly crashes. It would work some time and some times it won't.

I have ARC enabled.

Can't get what's wrong with just this simple code. Read a lot of questions on stack overflow, but none solve my problem.

EDIT: Stack Trace

2012-08-11 11:55:56.353 Magic Buzz[2088:707] (
    0   Magic Buzz                          0x000c7e19 -[gameOverScreen showStore:] + 700
    1   CoreFoundation                      0x3769c3fd -[NSObject performSelector:withObject:withObject:] + 52
    2   UIKit                               0x30891e07 -[UIApplication sendAction:to:from:forEvent:] + 62
    3   UIKit                               0x30891dc3 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30
    4   UIKit                               0x30891da1 -[UIControl sendAction:to:forEvent:] + 44
    5   UIKit                               0x30891b11 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 492
    6   UIKit                               0x30892449 -[UIControl touchesEnded:withEvent:] + 476
    7   UIKit                               0x3089092b -[UIWindow _sendTouchesForEvent:] + 318
    8   UIKit                               0x30890319 -[UIWindow sendEvent:] + 380
    9   UIKit                               0x30876695 -[UIApplication sendEvent:] + 356
    10  UIKit                               0x30875f3b _UIApplicationHandleEvent + 5826
    11  GraphicsServices                    0x3789222b PurpleEventCallback + 882
    12  CoreFoundation                      0x37716523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 38
    13  CoreFoundation                      0x377164c5 __CFRunLoopDoSource1 + 140
    14  CoreFoundation                      0x37715313 __CFRunLoopRun + 1370
    15  CoreFoundation                      0x376984a5 CFRunLoopRunSpecific + 300
    16  CoreFoundation                      0x3769836d CFRunLoopRunInMode + 104
    17  GraphicsServices                    0x37891439 GSEventRunModal + 136
    18  UIKit                               0x308a4cd5 UIApplicationMain + 1080
    19  Magic Buzz                          0x000b094d main + 96
    20  Magic Buzz                          0x000b08e8 start + 40
)
2012-08-11 11:55:56.554 Magic Buzz[2088:707] *** -[storeSinglePlayer respondsToSelector:]: message sent to deallocated instance 0xf6cde30
mvb
  • 701
  • 1
  • 11
  • 20
  • Does your project implement ARC? – Tripti Kumar Aug 11 '12 at 06:09
  • Have you tried running with zombies? The easiest way to do that is to profile it on the simulator using the Zombies instrument. – rob mayoff Aug 11 '12 at 06:13
  • Also what's the stack trace of the “message sent to deallocated instance” error? – rob mayoff Aug 11 '12 at 06:14
  • @robmayoff: Yes I have tried running with the NSZombies. After I enabled NSZombies, I got this 'deallocated instance' message. Earlier I was getting EXC_BAD_ACCESS – mvb Aug 11 '12 at 06:15
  • Try cleaning and quitting and then re-running your app? – Tripti Kumar Aug 11 '12 at 06:17
  • @iPhoneDeveloper: Done Re-running the app after and cleaning and quitting. But the same error. – mvb Aug 11 '12 at 06:22
  • can you find out which object has this memory allocation : 0xe5f6160 by using break-points? – Tripti Kumar Aug 11 '12 at 06:24
  • @robmayoff: added the stack trace – mvb Aug 11 '12 at 06:26
  • @iPhoneDeveloper: The crash happens when the showStore is executed. In fact I am confused now, the crash is happening both ways. It happens even when I click back. – mvb Aug 11 '12 at 06:38
  • Since `showStore:` doesn't send `respondsToSelector:`, that stack trace is not enough information. Were you running a release build when you captured it? Run a debug build instead. – rob mayoff Aug 11 '12 at 06:44
  • @robmayoff: got that the problem is with canceling a server query. Unable to rectify it though. – mvb Aug 11 '12 at 06:53

1 Answers1

2

some asynchronous method is calling storeSinglePlayer object after it deallocated, Try removing all the delegates to nil in ViewDidUnload/ViewWillDisappear. If you sending the some query to server and without waiting for it you press the Back button then also it will crash as after completing the request it will call storeSinglePlayer object. Hope this helps

Manish Agrawal
  • 10,958
  • 6
  • 44
  • 76
  • You are right, I have to get the pricing of the products through the iTunes Connect in my In App Purchase Store. And if I allow the prices to load and then press the back button, the crash doesn't happen. But then again, I get the crash at the execution of 'showStore'. – mvb Aug 11 '12 at 06:30
  • I am trying to fix the problem. The crash error is the same. I found a similar question on stack overflow: http://stackoverflow.com/questions/4782214/iphone-skproductsrequest-and-message-sent-to-deallocated-instance – mvb Aug 11 '12 at 06:52
  • I am unable to cancel the server query. I think that is the issue now. – mvb Aug 11 '12 at 06:53
  • instead of cancel the server query, hold the user to that page until request successfully completed or failed with error. – Manish Agrawal Aug 11 '12 at 07:35
  • The most weird thing is that, it works fine for about 10-15 clicks, without me changing anything. And suddenly, it would crash after that, throwing [storeSinglePlayer respondsToSelector:]: message sent to deallocated instance 0xe5f6160. And can't find a way to figure out failed In App Purchases queries. – mvb Aug 11 '12 at 08:00
  • its work fine for 10-15 clicks because during that time no response from server is coming as soon as response has come app will crashed. – Manish Agrawal Aug 11 '12 at 08:08
  • Thanks, it took me time, but I could solve the issue with hints from your answer. I was implementing some bad code that called viewDidLoad twice and it caused multiple requests to be sent to the server. As the response came from the server the app, crashed. – mvb Aug 16 '12 at 18:30
  • Resolved after setting tableView.delegate = nil in deinit. – Coder_A_D Sep 08 '15 at 09:40