不用:
使用
@implementation UIImage (DoNotCache)
+ (UIImage *)newImageNotCached:(NSString *)filename {
NSString *imageFile = [[NSString alloc] initWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], filename];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:imageFile];
[imageFile release];
return image;
}
@end
2、将View分成多个,不要在一个。
3、使用本地的
If you are autoreleasing lot of objects, you may run into situations where your objects may not be released until your program terminates. If so, think about using a local autorelease pool. Autorelease pools are staked, so if you create a new autorelease pool, it gets inserted into the top of the stack.
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *string = [[[NSString alloc] init] autorelease];
[pool drain];
4、记得及时释放
NSMutableArray *array = [[NSMutableArray alloc] init];
// obj has retain count of +1
MyObject *obj = [[MyObject alloc] init];
// obj has retain count of +2, so make sure to release it
[array addObject:array];
// obj has retain count of +1
[obj release];
http://www.uchidacoonga.com/2009/08/handling-didreceivememorywarning/
http://www.bdunagan.com/2008/10/01/triggering-didreceivememorywarning-on-the-iphone/
Now that the NDA is
However, getting your warning to propagate through your objects like a real warning does is a bit tricky. You have to use an undocumented notification message: UIApplicationMemoryWarni
Putting that method on a timer allows you to trigger a low memory warning throughout your application at a regular interval. For some reason, it doesn’t trigger the warning in your base controller, but you can easily add that class as an observer to that notification.
This process should allow you to trigger a didReceiveMemoryWarning notification throughout your iPhone application just like a real warning. The fact that it’s undocumented is okay because it’s only for testing purposes.