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.
更多推荐
发布评论