2011-05-19 92 views
0

我的didReceiveMemoryWarning應該是什麼?我沒有看到任何我可以釋放的東西,但仍然記憶猶新。我爲我的managedObjectContext設置了一個屬性,對於ivars來說就是這樣。didReceiveMemoryWarning trouble

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

回答

2

什麼是SHK,讓你flushOfflineQueue和clearNullWorkouts做什麼?這些可能是您在didReceiveMemoryWarning期間需要釋放的資源。也只是因爲didReceiveMemoryWarning火併不意味着你必須清理任何東西,例如,如果你仍然在顯示視圖,播放被引用的音頻文件等等。當這個調用你需要發佈的東西,如圖像不是正在播放的音頻等等。在didReceiveMemoryWarning被稱爲視圖控制器之後,未顯示的視頻將調用viewDidUnload,這就是您將所有IBOutlets /編程視圖設置爲零並釋放更多內存的位置。蘋果在Memory Management Programming Guide中討論了這一點。