Fix memorywarning cache flush

This commit is contained in:
Yann Diorcet 2012-10-22 12:03:34 +02:00
parent 36d8367802
commit 2834b69318
4 changed files with 23 additions and 15 deletions

View file

@ -74,8 +74,6 @@
- (UIViewController *)getCachedController:(NSString*)name;
- (UIViewController *)getCurrentViewController;
- (UIInterfaceOrientation)currentOrientation;
#ifdef DEBUG
- (void)clearCache;
#endif
- (void)clearCache:(NSArray*)exclude;
@end

View file

@ -244,11 +244,6 @@
return NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
[self clearCache];
}
#pragma mark - Event Functions
@ -265,18 +260,29 @@
#pragma mark -
- (void)clearCache {
- (void)clearCache:(NSArray *)exclude {
for(NSString *key in [viewControllerCache allKeys]) {
UIViewController *vc = [viewControllerCache objectForKey:key];
if(vc != self.stateBarViewController &&
vc != self.tabBarViewController &&
vc != self.contentViewController) {
bool remove = true;
if(exclude != nil) {
for (UICompositeViewDescription *description in exclude) {
if([key isEqualToString:description.content] ||
[key isEqualToString:description.stateBar] ||
[key isEqualToString:description.tabBar]
) {
remove = false;
break;
}
}
}
if(remove) {
[LinphoneLogger log:LinphoneLoggerDebug format:@"Free cached view: %@", key];
UIViewController *vc = [viewControllerCache objectForKey:key];
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 5.0) {
[vc viewWillUnload];
}
[vc viewDidUnload];
[viewControllerCache removeObjectForKey:key];
}
[viewControllerCache removeObjectForKey:key];
}
}

View file

@ -267,6 +267,10 @@ static PhoneMainView* phoneMainViewInstance=nil;
return [mainViewController currentOrientation];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
[mainViewController clearCache:viewStack];
}
#pragma mark - Event Functions

View file

@ -639,7 +639,7 @@ static UICompositeViewDescription *compositeDescription = nil;
[[LinphoneManager instance] destroyLibLinphone];
[LinphoneManager instanceRelease];
} else if([key isEqual:@"clear_cache_button"]) {
[[PhoneMainView instance].mainViewController clearCache];
[[PhoneMainView instance].mainViewController clearCache:[NSArray arrayWithObject:[[PhoneMainView instance] currentView]]];
} else if([key isEqual:@"battery_alert_button"]) {
[[UIDevice currentDevice] _setBatteryState:UIDeviceBatteryStateUnplugged];
[[UIDevice currentDevice] _setBatteryLevel:0.09f];