Iphone Xcode分配工具-侦听内存警告

Iphone Xcode分配工具-侦听内存警告,iphone,ios,objective-c,xcode,memory-management,Iphone,Ios,Objective C,Xcode,Memory Management,我正在使用分配工具来提高我的应用程序的性能。我想注意记忆警告,以确保我的应用程序不会占用太多内存或崩溃 我希望我的整个应用程序都能听到记忆分享。我知道我可以用它来监听某些警告,但是下面的代码会监听所有的内容吗?另外,我需要在哪里实施它?我需要把它放在每个视图控制器中还是可以放在应用程序代理中 - (id)init { if ((self = [super init])) { _cache = [NSMutableDictionary new]; [[NSNotifica

我正在使用分配工具来提高我的应用程序的性能。我想注意记忆警告,以确保我的应用程序不会占用太多内存或崩溃

我希望我的整个应用程序都能听到记忆分享。我知道我可以用它来监听某些警告,但是下面的代码会监听所有的内容吗?另外,我需要在哪里实施它?我需要把它放在每个视图控制器中还是可以放在应用程序代理中

- (id)init {
if ((self = [super init])) 
    {
    _cache = [NSMutableDictionary new];
    [[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(memoryWarning:) 
    name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
    }
return self;
}
我知道我需要实现倾听记忆警告的方法。这会听所有的记忆警告吗?另外,我是否需要在每个viewController中都放置此项?或者我可以把它放在AppDelegate中吗

- (id)init {
if ((self = [super init])) 
    {
    _cache = [NSMutableDictionary new];
    [[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(memoryWarning:) 
    name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
    }
return self;
}
- (void)memoryWarning:(NSNotification*)note {
    [_cache removeAllObjects];
}

任何指导都会很好!谢谢大家!

您的视图控制器已具有侦听内存警告的方法

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

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

谢谢,我需要呼叫[_cacheremoveallobjects];在didReceiveMemoryWarning方法中?否。
[\u缓存释放]
。它将在_缓存字典yya.中的所有对象上发送释放消息。。我不知道你缓存的目的
didReceiveMemoryWarning
方法在内存充足时由系统调用。如果需要进一步缓存,请不要等待
didReceiveMemoryWarning
释放
dealloc
中的_缓存。老实说,我不知道我为什么需要它-根据一个教程,建议在内存警告后清除缓存,我建议更改方法并使用它。当应用程序内存不足时,它会自动删除不需要的缓存项。