iOSDevSF
iOSDevSF

Reputation: 1179

didReceiveMemoryWarning trouble

What should be in my didReceiveMemoryWarning? I do not see anything I can release that is still in memory. I have a property set up for my managedObjectContext, that's it for ivars.

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *calendar = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"calendar.png"]style:UIBarButtonItemStyleBordered target:self action:@selector(viewCal)];
    self.navigationItem.rightBarButtonItem = calendar;
    [calendar release];

    UIBarButtonItem *settings = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"gears.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(viewSettings)];
    self.navigationItem.leftBarButtonItem = settings;
    [settings release];

    [SHK flushOfflineQueue];
    [self clearNullWorkouts];
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

Upvotes: 0

Views: 851

Answers (1)

Joe
Joe

Reputation: 57179

What is in SHK that makes you flushOfflineQueue and what does clearNullWorkouts do? Those may be the kind of resources that you need to free during didReceiveMemoryWarning. Also just because didReceiveMemoryWarning fires that does not mean you have to clean up anything, for instance if you are still displaying the view, playing an audio file that is being referenced, etc. When this called you need to release things like images that are not being displayed, audio that is not being played, etc. After didReceiveMemoryWarning is called view controllers that are not being displayed will have viewDidUnload called and that is where you will set all IBOutlets/programmatic views to nil and release more memory. Apple discusses this in the Memory Management Programming Guide.

Upvotes: 2

Related Questions