0

-Using ARC

-I have 5 separate view controllers all subclassing a class I made called "UIViewControllerWithLoadingView" which subclasses UIViewController.

-In both the subclasses and superclass I allocate and deallocate properties like this:

@property (strong, nonatomic) NSURLConnection *urlConnection;

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.urlConnection=nil;
}

-Now when didReceiveMemoryWarning is called, the sub classes viewDidUnload method acts fine. BBBUUTTT if I set properties to nil in the super class, UIViewControllerWithLoadingView, the application will crash. Particularly right where I set the properties of the sub class to nil. So for right now I just don't set the properties to nil in the superclass, which becomes problematic because the live bytes just keep piling up at run time.

MobileMon
  • 8,341
  • 5
  • 56
  • 75
  • 2
    What is the exception you get on a crash? (If it doesn't tell you already, use @try/@catch to find out.) – Phillip Mills Jul 23 '12 at 12:26
  • "Thread 1: EXC_BAD_ACCESS (code=2,address=0x8)" I'm unable to get the description of the exception because the app crashes before I can log it – MobileMon Jul 23 '12 at 12:41
  • Set a breakpoint on Objective-C exceptions using the Breakpoint navigator **or** put the @try/@catch around the first line of the program (in main.m). – Phillip Mills Jul 23 '12 at 12:46
  • Still won't print the exception...tried in both simulator and physical device. The app just crashes before printing – MobileMon Jul 23 '12 at 14:33
  • I don't think this exception can be raised by NSException. Certain exceptions can't be caught, objective c doesn't work like Java where it catches anything – MobileMon Jul 23 '12 at 18:18
  • I believe that if it's an exception that's thrown after the app starts to execute `main` it can be caught. Sometimes apps are killed by signals, however, and sometimes they fail during launch. Those are tough to diagnose. – Phillip Mills Jul 23 '12 at 18:29

2 Answers2

0

The rule of thumb is that methods that "clean up"--like dealloc or viewDidUnload--should make the call to super after they do everything else. (And methods that "set up"--like init--call to super first.) I can't tell if that's your problem without seeing all your subclass implementations, but that would be a place to start.

Husker Jeff
  • 857
  • 1
  • 5
  • 6
  • Although I did have some super calls in the wrong place according to your comments, this still did not fix the problem – MobileMon Jul 23 '12 at 14:33
0

The problem was in the superclass I had a view that extended uiview which had a property reference to the viewcontroller. Well dealloc is automatically called in arc so dealloc would actually set the viewcontroller itself to nil causing a crash. Once I removed the property of the viewcontroller in the custom view class the problem no longer occurred

MobileMon
  • 8,341
  • 5
  • 56
  • 75