ARC中的'[[something retain] autorelease]相当于什么? [英] What's the equivalent of '[[something retain] autorelease]' in ARC?

查看:91
本文介绍了ARC中的'[[something retain] autorelease]相当于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ARC中的 [[something retain] autorelease] 相当于什么?

What's the equivalent of [[something retain] autorelease] in ARC?

我遇到问题DBRequest类调用我的委托表示完成。我的委托然后将DBRequest实例设置为nil,dealloc就是它。但是当堆栈从我的委托中弹出并跳回到DBRequest时,它当然会崩溃。

I have a problem where a class DBRequest calls my delegate to signify completion. My delegate then sets the DBRequest instance to nil, which dealloc's it. But then when the stack pops out of my delegate and jumps back to the DBRequest, it of course then crashes.

如果我不在ARC,在我的代表中我在发布对它的引用之前,只需执行 [[theDbRequest retain] autorelease] ,这样它就能存活足够长的时间直到下一个运行循环自动释放它。

If I wasn't in ARC, in my delegate I'd simply do [[theDbRequest retain] autorelease] before releasing my reference to it, so that it'd survive long enough until the next run loop autoreleased it.

我应该在ARC做什么?

What should I do in ARC?

推荐答案

如何添加类似

__strong DBRequest * myself = self;
[delegate reportDone];

我认为这会增加自我对象,直到函数结束,防止它早死。

I think that'll increment the self object until the end of the function preventing it from dying early.

这篇关于ARC中的'[[something retain] autorelease]相当于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆