Skip to content

Commit

Permalink
15 handle memory warnings
Browse files Browse the repository at this point in the history
- use app Delegate instead notification centre
  • Loading branch information
gmarik committed Feb 21, 2012
1 parent dbef498 commit f3cdf78
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 15-SavingLoadingAndMultitasking/Homepwner/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "AppDelegate.h"
#import "ItemsViewController.h"
#import "PosessionStore.h"
#import "ImageStore.h"

@implementation AppDelegate

Expand Down Expand Up @@ -39,4 +40,9 @@ -(void)applicationWillTerminate:(UIApplication *)application {
// [self applicationDidEnterBackground:application];
}

-(void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
NSLog(@"Received mem warning");
[ImageStore.defaultStore clearCache];
}

@end
1 change: 1 addition & 0 deletions 15-SavingLoadingAndMultitasking/Homepwner/ImageStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
-(void)setImage:(UIImage *)i forKey:(NSString *)s;
-(UIImage *)imageForKey:(NSString *)s;
-(void)deleteImageForKey:(NSString *)s;
-(void)clearCache;

@end
5 changes: 5 additions & 0 deletions 15-SavingLoadingAndMultitasking/Homepwner/ImageStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ -(void)deleteImageForKey:(NSString *)s
[NSFileManager.defaultManager removeItemAtPath:path error:NULL];
}

-(void)clearCache {
NSLog(@"[ImageStore] clearCache");
[dict removeAllObjects];
}


// init
- (id)init {
Expand Down

0 comments on commit f3cdf78

Please sign in to comment.