免费()不释放内存? [英] free() not deallocating memory?
本文介绍了免费()不释放内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
free(str);
printf("%d\n", str->listeners);
对printf的调用成功(如做其他任何调用STR的成员)。这怎么可能?
The call to printf succeeds (as do any other calls to str's members). How is this possible?
推荐答案
您只差(联合国)幸运。这code表现出不确定的行为 - 任何事情都有可能发生,包括寻找像内存中不释放
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.
这篇关于免费()不释放内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文