2

I'm having a problem with my iPhone App, I'm getting EXC_BAD_ACCESS, I had some memory leaks, but these are now fixed, so I'm not sure whats going on. I realise that I haven't provide a lot of information, but I really don't know whats happening.

The initial screen opens up where I have a number of buttons. Tapping on the first button, which runs the following code and opens up a modal view:

-(IBAction)newWorkoutButton
{
    newWorkoutViewController .loadedFromRootViewController = @"YES";
    [self presentModalViewController:newWorkoutViewController animated:YES];
}

The screen freezes and the is in the code below:

#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <CoreLocation/CoreLocation.h>


int main(int argc, char *argv[]) 
{
    Method getDistanceFrom = class_getInstanceMethod([CLLocation class], @selector(getDistanceFrom:));
    class_addMethod([CLLocation class], @selector(distanceFromLocation:), method_getImplementation(getDistanceFrom), method_getTypeEncoding(getDistanceFrom));

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil); // ERROR HAPPENING HERE
    [pool release];
    return retVal;
}
Scott Harwell
  • 7,457
  • 2
  • 28
  • 41
Stephen
  • 4,715
  • 8
  • 53
  • 78
  • 1
    Enable "zombie" mode and run your program again - you will see exactly what/where the error occurs. See http://stackoverflow.com/questions/2190227/how-do-i-set-nszombieenabled-in-xcode-4 on how to enable this mode. – Aleks G Jan 14 '12 at 15:00
  • Out of interest what are you trying to achieve with the `class_getInstanceMethod`/`class_addMethod` stuff? – Paul.s Jan 14 '12 at 15:03
  • you may be releasing some autoreleased object .. It will be better if you can give the crashlog .. – Ali3n Jan 14 '12 at 15:11
  • Where is your newWorkoutViewController allocated? – Aaron Hayman Jan 14 '12 at 15:20

1 Answers1

1

Like Aleks suggested you can try to find the zombie like this:

I find this alternative more convenient:

  1. Click the "Run Button Dropdown"
  2. From the list choose Profile
  3. The program "Instruments" should open where you can also choose Zombies
  4. Now you can interact with your app and try to cause the error
  5. As soon as the error happens you should get a hint on when your object was released and therefore deallocated.

Zombies
(source: dimzzy.com)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Besi
  • 22,579
  • 24
  • 131
  • 223