free()不解除内存?(free() not deallocating memory?)

编程入门 行业动态 更新时间:2024-10-28 12:18:15
free()不解除内存?(free() not deallocating memory?) free(str); printf("%d\n", str->listeners);

对printf的调用成功(对str的成员的任何其他调用也是如此)。 这怎么可能?

free(str); printf("%d\n", str->listeners);

The call to printf succeeds (as do any other calls to str's members). How is this possible?

最满意答案

你只是(不)幸运。 该代码表现出未定义的行为 - 任何事情都可能发生,包括看起来没有释放内存。

内存释放,但积极清除它没有意义,因此其原始内容可能仍然存在。 但你不能依赖它。

You're just (un)lucky. That code exhibits undefined behavior - anything can happen, including looking like the memory wasn't freed.

The memory is freed, but there is no point in actively clearing it, so its original content is likely to still be there. But you can't rely on that.

更多推荐

本文发布于:2023-08-06 07:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1445306.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内存   free   memory   deallocating

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!