objective-ciosdeallocdidreceivememorywarningviewdidunload

didReceiveMemoryWarning Crash


-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.


Solution

  • 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