ARC下面的对象被释放的bug
一般在ARC管理的方式之下,很难出现对象被过度释放的问题,下面是我将遇到的一个crash。
* thread #: tid = 0x31d1db, 0x0000000102e5e00b libobjc.A.dylib`objc_msgSend + , queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=, address=0x18)
frame #: 0x0000000102e5e00b libobjc.A.dylib`objc_msgSend +
frame #: 0x0000000101968212 UIKit`-[UISectionRowData refreshWithSection:tableView:tableViewRowData:] +
frame #: 0x000000010196de45 UIKit`-[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] +
frame #: 0x000000010196df3a UIKit`-[UITableViewRowData heightForTable] +
frame #: 0x00000001017c0af0 UIKit`-[UITableView _updateContentSize] +
frame #: 0x00000001017ddecd UIKit`-[UITableView didMoveToWindow] +
frame #: 0x00000001017649a0 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] +
frame #: 0x0000000101775333 UIKit`-[UIScrollView _didMoveFromWindow:toWindow:] +
frame #: 0x000000010176468e UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] +
frame #: 0x000000010176468e UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] +
frame #: 0x000000010176468e UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] +
frame #: 0x000000010176468e UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] +
frame #: 0x000000010175d112 UIKit`__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke +
frame #: 0x000000010175d086 UIKit`-[UIView(Hierarchy) _postMovedFromSuperview:] +
frame #: 0x0000000101766f4b UIKit`-[UIView(Internal) _addSubview:positioned:relativeTo:] +
frame #: 0x00000001017c816f UIKit`-[UITableView _addContentSubview:atBack:] +
frame #: 0x00000001017e08cd UIKit`__53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke +
frame #: 0x00000001017615ce UIKit`+[UIView(Animation) performWithoutAnimation:] +
frame #: 0x00000001017dff5b UIKit`-[UITableView _configureCellForDisplay:forIndexPath:] +
frame #: 0x00000001017e74cc UIKit`-[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] +
frame #: 0x00000001017c6fb1 UIKit`-[UITableView _updateVisibleCellsNow:isRecursive:] +
frame #: 0x00000001017dce3c UIKit`-[UITableView layoutSubviews] +
frame #: 0x0000000101769973 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] +
frame #: 0x00000001043efde8 QuartzCore`-[CALayer layoutSublayers] +
frame #: 0x00000001043e4a0e QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) +
frame #: 0x00000001043e487e QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) +
frame #: 0x000000010435263e QuartzCore`CA::Context::commit_transaction(CA::Transaction*) +
frame #: 0x000000010435374a QuartzCore`CA::Transaction::commit() +
frame #: 0x00000001016ee54d UIKit`-[UIApplication _reportMainSceneUpdateFinished:] +
frame #: 0x00000001016ef238 UIKit`-[UIApplication _runWithMainScene:transitionContext:completion:] +
frame #: 0x00000001016edbf2 UIKit`-[UIApplication workspaceDidEndTransaction:] +
frame #: 0x000000010480c2a3 FrontBoardServices`__31-[FBSSerialQueue performAsync:]_block_invoke +
frame #: 0x00000001034f253c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ +
frame #: 0x00000001034e8285 CoreFoundation`__CFRunLoopDoBlocks +
frame #: 0x00000001034e8045 CoreFoundation`__CFRunLoopRun +
frame #: 0x00000001034e7486 CoreFoundation`CFRunLoopRunSpecific +
frame #: 0x00000001016ed669 UIKit`-[UIApplication _run] +
frame #: 0x00000001016f0420 UIKit`UIApplicationMain +
* frame #: 0x0000000101513903 NiuHelper`main(argc=, argv=0x00007fff5e7ac350) + at main.m:
frame #: 0x000000010844d145 libdyld.dylib`start +
看问题还以为是苹果的bug,搜索一番之后看到一个人遇到同样的问题,一个网友给出的回复是:
Sorry I never came back to this thread. So the issue is that this nib is being loaded by a view controller through its initWithNibName:bundle: method. That method will not retain any top level objects on its own. So your Highscore Controller object is loaded from the nib and then autoreleased, which means it goes away pretty quickly after that. So you need to retain that object. One easy way to do that is to define a property in your view controller subclass for this object (specifying 'retain' and 'IBOutlet' of course) and then connect that outlet to this Highscore Controller in IB.
联想到自己这里创建了一个VC,将VC的view添加到界面中就没有管这个VC了,VC被释放,看来要好好注意这种autorelease的问题了,即使是在同一个线程中还是可能存在问题。
- (TopTabPage *)TopTabControl:(TopTabControl *)tabCtrl
pageAtIndex:(NSUInteger)index
{
TopTabPage *page = [[TopTabPage alloc] initWithFrame:CGRectMake(,
,
CGRectGetWidth(self.view.frame),
CGRectGetHeight(tabCtrl.bounds) -
)]; NHNewsModel *NewsModel = [self.tagListModel.result.channelList objectAtIndex:index];
NHNewsContentViewController *contentViewVC = [[NHNewsContentViewController alloc] initWithChannelID:NewsModel.getChannelID
andContentRect:page.bounds];
[page addSubview:contentViewVC.view]; // [_array addObject:contentViewVC];
return page;
}
将VC retain之后就没有问题了。苹果的arc也不能完全相信啊。
ARC下面的对象被释放的bug的更多相关文章
- java 哪些情况下会使对象锁释放
Java_多线程_锁释放 问:Java多线程运行环境中,在哪些情况下会使对象锁释放?答:由于等待一个锁的线程只有在获得这把锁之后,才能恢复运行,所以让持有锁的线程在不再需要锁的时候及时释放锁是很重要的 ...
- GDI 对象的释放与内存泄漏的问题研究
最近写了一个GDI 绘图的程序,过程中遇到一个奇怪的问题,就是 定时器定时一会GDI绘的图就消失了..后来经过分析,原来是 GDI对象数量过多 ,即GDI对象超过10000个 导致内存泄漏的问题.找到 ...
- C#+ArcEngine中com对象的释放问题
1.问题描述 最近在写C#下AE的开发,在循环获取数据并修改时碰到了两个问题"超出系统资源"和"超出打开游标最大数":在网上看了一些资料,发现都是说在循环中没有 ...
- 对象的notify方法的含义和对象锁释放的三种情况
1,notify的含义 (1)notify一次只随机通知一个线程进行唤醒 (2)在执行了notify方法之后,当前线程不会马上释放该对象锁,呈wait状态的线程也不能马上获得该对象锁, 要等到 ...
- EasyDarwin开源流媒体服务器中一种实现对作用域内new对象自动释放的方法(值得借鉴)
我们经常在开发过程中,在局部new了一个对象,我们就会在复杂的逻辑过程中担心这个对象是否已经被释放,需要在一大堆的if.else.while.break进行判断new对象是否还存在,或者相同的dele ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- 对象的释放Dispose和Close对比
C#内存释放的几个方法对比: 而Close与Dispose这两种方法的区别在于,调用完了对象的Close方法后,此对象有可能被重新进行使用:而Dispose方法来说,此对象所占有的资源需要被标记为无用 ...
- TDictionary字典 对象的释放。。。
type TRen = record name: string; age: Integer; end; type TPeople = class private Fname: string; Fage ...
- 解决JQUERY在IE8,7,6下将字符串转成XML对象时产生的BUG
js 定义一个xml 对象,var data = "<Root><DataRow Id=\"1234\"/></Root>" ...
随机推荐
- CentOS7 离线安装gcc/pcre-devel/openssl-devel/zlib-devel
1. 解压CentOS7操作系统安装镜像,进入到CentOS-7.0-1406-x86_64-DVD\Packages目录,这下面存储了很多rpm包. 2. 找到下面列出的rpm包,上传到CentOS ...
- MATLAB中的多项式运算
作者:长沙理工大学 交通运输工程学院 王航臣 1.多项式求根 在MATLAB中求取多项式的根用roots函数. 函数:roots 功能:一元高次方程求解. 语法:roots(c) 说明:返回一个列向量 ...
- mysql与oracle在groupby语句上的细节差异
前言 之所以去纠那么细节的问题,是因为之前有过一个这样的场景: 有个同学,给了一条数据库的语句给我,问,为啥这样子的语句在oracle语句下执行不了. select * from xx where x ...
- Vultr新加坡机房速度怎么样?值得购买吗?最新评测!
2016年9月,Vultr vps开通了新加坡Singapore机房线路.与知名的竞争对手Digitalocean和Linode一样,新加坡机房对亚洲速度友好,是讨用户欢心的一个进步. 但是,vult ...
- CSU 1811 Tree Intersection
莫队算法,$dfs$序. 题目要求计算将每一条边删除之后分成的两棵树的颜色的交集中元素个数. 例如删除$u->v$,我们只需知道以$v$为$root$的子树中有多少种不同的颜色(记为$qq$), ...
- 去掉UItableview section headerview黏性
UITabelView在style为plain时,在上拉是section始终粘在最顶上而不是跟随滚动而消失或者出现 可以通过设置UIEdgeInsetsMake: - (void)scrollView ...
- 编写CodeMirror Modes详解
在写新的模式(mode)之前,还是先来概括一下CodeMirror的设计思路.CodeMirror分为三部分:核心,模式,扩展.核心库对外开放了很多接口,而这些接口就是实现新模式或者新扩展的基石. 在 ...
- [SOJ] can I post the letter?
1155. Can I Post the letter Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description I am a t ...
- HashMap按键排序和按值排序
对map集合进行排序 今天做统计时需要对X轴的地区按照地区代码(areaCode)进行排序,由于在构建XMLData使用的map来进行数据统计的,所以在统计过程中就需要对map进行排序. 一.简单 ...
- [Jmeter]jmeter之参数化
一.同一个服务器不同界面访问 a 准备工作: 1.启动jmeter: 2.创建需要访问的url文件,内容示例如下: 即比如:http://www.cnblogs.com/amberly/p/59651 ...