OC编码时候,会走入一些理解误区或养成的错误的编码习惯.特记录下
1.加载重复的图片就使用[UIImage imageNamed:@"xxx.png"],特别是在UITableViewCell中要使用[UIImage imageNamed:@"xxx.png"]
2.加载一次性图片,就使用[UIImage imageWithData]
NSString *path = [[NSBundle mainBundle] pathForResource:@"xxx" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:path];
[UIImage imageWithData:imageData];
3.
//MRC下
self.deviceIds = [[NSMutableArray alloc] init];
这样会造成内存泄露
正确方式:
NSMutableArray *array = [[NSMutableArray alloc] init];
self.deviceIds = array;
4.@autoreleasepool里面最好不要加入循环,这样造成内存急速增加
@autoreleasepool {
for (int i = 0; i < 10; i++) {
//处理
}
}