在 Objective-c 中释放对象时实际上会发生什么?

发布于 2024-12-07 14:16:10 字数 237 浏览 1 评论 0原文

我想在较低的层面上了解 Objective-c 的内存管理。假设我在堆上分配了 100 个字节给某个 Objective-c 对象。 当对象被dealloc'd时,这个100字节块会发生什么?

我很好奇运行时如何知道内存块可以在释放后重新使用它已dealloc了。实际字节会发生什么?它们是否设置为随机值?或者它们可能会保留自己的值,但稍后会被其他对象覆盖。

I'd like to understand Objective-c's memory management at a lower level. Say I have 100 bytes allocated on the heap to some Objective-c object. What happens to this 100 byte block when the object is dealloc'd?

I'm curious about how the runtime knows that a block of memory is available for re-use after it's dealloc'd. What happens to the actual bytes? Are they set to random values? Or perhaps they keep their values and just get overwritten by other objects later.

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

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

发布评论

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

评论(1

情栀口红 2024-12-14 14:16:10

它们保留其值,但被标记为未使用和可覆盖。

这种行为就像 malloc 和 malloc 一样。 C 中的自由函数

They keep their value but are marked as unused and overridable.

This behavior is just like the malloc & free functions in C.

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