iOS避免内存警告的一些建议
来源:互联网 发布:万网域名指向花生壳 编辑:程序博客网 时间:2024/05/15 04:38
不用:
使用
@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 +1MyObject *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.
- iOS避免内存警告的一些建议
- iOS避免内存警告的一些建议
- iOS避免内存警告的一些建议
- Android 使用 Handler 避免内存泄漏的一些建议
- iOS当发生内存警告时的一些处理
- iOS内存警告的等级
- iOS内存警告的等级
- iOS内存警告的等级
- 堆内存的一些建议!
- 关于IOS应用接收到内存警告时的一些内幕
- iOS相机内存警告的解决办法
- iOS 加载图片时的内存警告
- iOS 收到内存警告的处理过程
- Android性能优化之避免内存泄漏的建议
- iOS内存警告
- iOS内存警告
- iOS内存警告
- iOS内存警告
- PAT 1028. List Sorting (25) 重写sort 函数中的cmp
- thinkphp3.0中examples出现的各种问题,rbac直接打不开?
- 关于strlen()
- 网络编程常用接口的内核实现----sys_socket()
- RF kill switch support
- iOS避免内存警告的一些建议
- UML——时序图
- javascript循环绑定事件,只返回最后一个实例,解决办法
- HDU 1829 A Bug's Life
- 完整 httpd.conf 配置详情及中文注解
- ios 真机调试的细节
- Gallay
- hdu 2818 Building Block(并查集,输出一元素下边有多少)
- 加速Web开发的9款知名HTML5框架