一般在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的更多相关文章

  1. java 哪些情况下会使对象锁释放

    Java_多线程_锁释放 问:Java多线程运行环境中,在哪些情况下会使对象锁释放?答:由于等待一个锁的线程只有在获得这把锁之后,才能恢复运行,所以让持有锁的线程在不再需要锁的时候及时释放锁是很重要的 ...

  2. GDI 对象的释放与内存泄漏的问题研究

    最近写了一个GDI 绘图的程序,过程中遇到一个奇怪的问题,就是 定时器定时一会GDI绘的图就消失了..后来经过分析,原来是 GDI对象数量过多 ,即GDI对象超过10000个 导致内存泄漏的问题.找到 ...

  3. C#+ArcEngine中com对象的释放问题

    1.问题描述 最近在写C#下AE的开发,在循环获取数据并修改时碰到了两个问题"超出系统资源"和"超出打开游标最大数":在网上看了一些资料,发现都是说在循环中没有 ...

  4. 对象的notify方法的含义和对象锁释放的三种情况

    1,notify的含义     (1)notify一次只随机通知一个线程进行唤醒 (2)在执行了notify方法之后,当前线程不会马上释放该对象锁,呈wait状态的线程也不能马上获得该对象锁, 要等到 ...

  5. EasyDarwin开源流媒体服务器中一种实现对作用域内new对象自动释放的方法(值得借鉴)

    我们经常在开发过程中,在局部new了一个对象,我们就会在复杂的逻辑过程中担心这个对象是否已经被释放,需要在一大堆的if.else.while.break进行判断new对象是否还存在,或者相同的dele ...

  6. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  7. 对象的释放Dispose和Close对比

    C#内存释放的几个方法对比: 而Close与Dispose这两种方法的区别在于,调用完了对象的Close方法后,此对象有可能被重新进行使用:而Dispose方法来说,此对象所占有的资源需要被标记为无用 ...

  8. TDictionary字典 对象的释放。。。

    type TRen = record name: string; age: Integer; end; type TPeople = class private Fname: string; Fage ...

  9. 解决JQUERY在IE8,7,6下将字符串转成XML对象时产生的BUG

    js 定义一个xml 对象,var data = "<Root><DataRow Id=\"1234\"/></Root>" ...

随机推荐

  1. Angular 2.0 从0到1 (五)

    第一节:Angular 2.0 从0到1 (一)第二节:Angular 2.0 从0到1 (二)第三节:Angular 2.0 从0到1 (三)第四节:Angular 2.0 从0到1 (四)第五节: ...

  2. Attempt to write to field 'android.support.v4.app.FragmentManagerImpl android.support.v4.app.Fragment.mFragmentManager' on a null object reference

    E/AndroidRuntime﹕ FATAL EXCEPTION: mainProcess: org.example.magnusluca.drawertestapp, PID: 3624java. ...

  3. CodeForces 669C Little Artem and Matrix GNU

    模拟. 把操作记录一下,倒着复原回去. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cs ...

  4. hdu1035

    #include<stdio.h>#include<string.h>int step,n,m;int a[1010][1010];char map[11][11];void ...

  5. 在CentOS上安装第三方软件库EPEL

    Extra Packages for Enterprise Linux (EPEL)[企业版 Linux 附加软件包(以下简称 EPEL)]是一个由特别兴趣小组创建.维护并管理的,针对 红帽企业版 L ...

  6. c#弱事件(weak event)

    传统事件publisher和listener是直接相连的,这样会对垃圾回收带来一些问题,例如listener已经不引用任何对象但它仍然被publisher引用 垃圾回收器就不能回收listener所占 ...

  7. sql优化--in和exists效率

    系统要求进行SQL优化,对效率比较低的SQL进行优化,使其运行效率更高,其中要求对SQL中的部分in/not in修改为exists/not exists 修改方法如下: in的SQL语句 SELEC ...

  8. <验证码的产生>C语言---验证码的产生和验证

    无论在网页还是软件上登录时候都会遇到验证码的问题,不知道不懂其中奥秘的码友有没有兴趣一起来探讨一下. 其实并没有什么奥秘可言,就是产生随机数,然后让产生的随机数做为字符库(提前做好的数字字母字符串)的 ...

  9. Ansible Lookup

    1.  文件内容的读取 --- - hosts: all vars: contents: "{{ lookup('file', '/etc/foo.txt') }}" tasks: ...

  10. 6、iOS快速枚举

    今天在写程序的时候想在当前视图跳转的时候释放掉当前视图上面add的一些子视图.因为add的子视图有些是在别的类里面add进来的,当前页面不知道自己当前有哪几个类型的子视图.这样,我就想到了用循环遍历来 ...