iOS Memory Leaks with [[NSBundle mainBundle] loadNibNamed:owner:options:]
来源:互联网 发布:附加数据库错误602 编辑:程序博客网 时间:2024/05/19 00:17
http://senry.me/post/2012-12-21/40047740239
一直在用XIB中写很多UIView的内容以便重用和管理,但是最近写的有一系列XIB实现的View发现在Instruments有大量内存泄露。抽出的大概内容如下:
+ (SGXView *)getContactViewFromXibWithModel:(SGXModel *)model
{
SGXView *view = nil;
NSArray *nibArray = [[NSBundlemainBundle] loadNibNamed:@"SGXView"owner:selfoptions:nil];//xib内的对象设置需要注意,不然会出错
for (id obj in nibArray)
{
if ([obj isKindOfClass:[SGXView class]])
{
view = obj;
break;
}
}
if (view)
{
view.model = model;
[view refreshView];
}
return view;
}
refreshView中的代码是简单的几个Label复制之类的,但是这一系列写的时候比较懒,以类局部变量的形式写IBOutlet,而不是以前用@property(assign)写的IBOutlet连接变量和XIB内的对象。
就是这么一个懒惰的行为导致了这一系列内存泄露,害我找了好久,又参照以前的写法,只对比出了以上连接变量的方法不同而已。虽然不是很明白为什么用@property就能防止不内存泄露,但是以后还是老老实实写标准代码吧~记录下,希望对未来有碰到相同泄露的网友有帮助。
- iOS Memory Leaks with [[NSBundle mainBundle] loadNibNamed:owner:options:]
- initWithNibName 和 [[NSBundle mainBundle] loadNibNamed] 的区别
- Swift写- (NSArray *)loadNibNamed:(NSString *)name owner:(id)owner options:(NSDictionary *)options
- IOS开发之 [[NSBundle mainBundle] infoDictionary]
- NSBundle、[NSBundle mainBundle] 详解
- Detecting memory leaks with HookLogger
- XCode ios iphone 资源文件管理 NSBundle mainBundle
- iOS开发.[NSBundle mainBundle] 通过pathForResource返回路径为空.
- IOS开发: NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]
- iOS开发.[NSBundle mainBundle] 通过pathForResource返回路径为空.
- iOS开发 [NSBundle mainBundle] 通过pathForResource返回路径为空.
- [NSBundle mainBundle] 详解
- NSBundle以及mainBundle
- [[NSBundle mainBundle] infoDictionary]
- [NSBundle mainBundle] 详解
- NSBundle mainBundle
- [[NSBundle mainBundle] infoDictionary]
- [[NSBundle mainBundle] infoDictionary]
- 如何解决SqlServer2008修改表结构后无法保存的问题
- expression cannot be evaluated
- 到底应该把网站放在哪里?
- android81--两个Activity之间跳转时必然会执行的是哪几个方法
- 1.认识类集
- iOS Memory Leaks with [[NSBundle mainBundle] loadNibNamed:owner:options:]
- android82--注册广播有几种方式
- 对缓存的思考——提高命中率(博主技术达人,需要关注!)
- 整型值和字符数组在内存中存储方式
- 文件例题(五)
- android83--横竖屏切换时候Activity的生命周期。
- android84--后台的Activity被系统 回收怎么办?
- ORACLE错误一览表
- 抽象数据类型Triplet的表示和实现