在 Objective-c 中释放对象时实际上会发生什么?
我想在较低的层面上了解 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们保留其值,但被标记为未使用和可覆盖。
这种行为就像 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.