谁负责释放iOS中Singleton类的内存?

发布于 2025-01-07 13:33:43 字数 305 浏览 2 评论 0原文

我正在检查如何在 iOS 上编写 Singleton 类。根据网站(http://www.galloway.me.uk/tutorials/ singleton-classes/),我知道如果不使用 ARC,我需要使用 allocWithZone 函数来分配我的类本身。

我的关键问题是...稍后如何释放我的类的内存(在 alloc 或 allocWithZone 之后)?谁对记忆负责?

谢谢。

I am checking on how to write Singleton class on iOS. According to the web site (http://www.galloway.me.uk/tutorials/singleton-classes/), I understand that without the use of ARC, I need to use allocWithZone function to allocate my class itself.

My key question is ... how can the memory of my class (after alloc or allocWithZone) be freed later ? Who is responsible for the memory ?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

习惯成性 2025-01-14 13:33:43

如果你想在 -(id) init 期间“释放内存”,你可以设置 self = nil;

if you want to "free the memory" during -(id) init you can set self = nil;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文