覆盖“发布"或“解除分配" [英] Override "release" or "dealloc"

查看:55
本文介绍了覆盖“发布"或“解除分配"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪种方法最好

覆盖目标 c 中的release"或dealloc"方法?

Override "release" or "dealloc" method in objective c?

为什么?

推荐答案

在非 ARC 下,99% 的情况下你不应该重写 release 方法.

Under non-ARC, 99% of the cases you should not override the release method.

我只见过一种需要重写 release 方法的情况——一种单例,无论你调用 alloc 多少次,它都会强制类只有一个实例.

I have seen only 1 case that the need to override the release method - a kind of singleton, which forces the class have really 1 single instance no matter how many times you call alloc.

这样不仅覆盖了 release 方法,还覆盖了 allowWithZone:retain、'retainCount` 等(实际上是实现那种单例并不常见)

That way override not only the release method, but also allowWithZone:, retain, 'retainCount`, etc. (It is actually not common to implement that kind of singleton)

这篇关于覆盖“发布"或“解除分配"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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