free()无法正确释放内存? [英] free() not freeing up memory properly?

查看:155
本文介绍了free()无法正确释放内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图释放用malloc分配的内存,但是根据Eclipse的调试器,free命令似乎不能正常工作.这怎么可能?

I'm trying to free up the memory I've allocated with malloc, but the free command doesn't seem to do its job properly according to Eclipse's debugger. How's this possible?

下面是我的调试器的屏幕快照,据说它释放了seCurrent->student->year,显然不是这种情况. year是使用malloc分配的.

Below is a screenshot of my debugger after it supposedly freed up seCurrent->student->year, which is clearly not the case. year was allocated using malloc.

替代文本http://img693.imageshack.us/img693/7840/codeo .png

推荐答案

free()通常不会更改程序中的任何值-只是对C运行时堆进行调整.这意味着将保留刚刚释放的内存中的值.但是,尝试从您的代码访问它们会导致未定义的行为.

free() does not normally change any values in your program - it just makes adjustments to the C runtime heap. This means that the values in the memory that was just freed are retained. However, attempts to access them from your code lead to undefined behaviour.

这篇关于free()无法正确释放内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆