为什么我的C程序没有按原样释放内存? [英] Why does my c program not free memory as it should?

查看:82
本文介绍了为什么我的C程序没有按原样释放内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用c编写了一个程序,想知道它使用了多少内存,并注意到在正常使用它时内存使用量会增加(在启动时它使用约250k,现在为1.5mb). afaik,我释放了所有未使用的内存,经过一段时间后,该应用使用了更少的内存.释放的内存是否可能仅从活动"内存变为有线"之类,以便在需要可用空间时将其释放? 顺便提一句.如果这很重要,我的机器可以在mac os x上运行.

I have made a program in c and wanted to see, how much memory it uses and noticed, that the memory usage grows while normally using it (at launch time it uses about 250k and now it's at 1.5mb). afaik, I freed all the unused memory and after some time hours, the app uses less memory. Could it be possible, that the freed memory just goes from the 'active' memory to the 'wired' or something, so it's released when free space is needed? btw. my machine runs on mac os x, if this is important.

推荐答案

如果您正在从操作系统中查看内存使用情况,则可能会看到此行为.释放的内存不会自动返回到操作系统,但通常会保留在进程中,并且可以在以后进行分配.您所看到的通常是内存使用量的高峰.

If you're looking at the memory usage from the OS, you are likely to see this behavior. Freed memory is not automatically returned to the OS, but normally stays with the process, and can be malloced later. What you see is usually the high-water mark of memory use.

正如Konrad Rudolph所建议的那样,请使用从过程内部检查内存的方法来查找内存链接.

As Konrad Rudolph suggested, use something that examines the memory from inside the process to look for memory links.

这篇关于为什么我的C程序没有按原样释放内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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