且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

代码示例:为什么我仍然可以访问此NSString对象后,我已经释放它?

更新时间:2023-11-12 22:35:22

你得到一个双重的免费错误,因为你释放两次,导致两个dealloc消息。 = P

You're getting a double free error because you are releasing twice and causing two dealloc messages. =P

请记住,只是因为释放并不意味着其内存地址上的数据立即被销毁。它只是被标记为未使用,所以内核知道,在未来的某个时候,它是免费的用于另一个数据。直到那一点(在你的应用程序空间中是完全不确定的),数据将保留在那里。

Keep in mind that just because you release doesn't doesn't mean the data at its memory address is immediately destroyed. It's just being marked as unused so the kernel knows that, at some point in the future, it is free to be used for another piece of data. Until that point (which is totally nondeterministic in your app space), the data will remain there.

再次:release(和dealloc'ing)数据破坏在字节级别。它只是内核的标记。

So again: releasing (and dealloc'ing) doesn't necessitate immediate data destruction on the byte level. It's just a marker for the kernel.