蓝森林首页 | 返回主页 | 本站地图 | 站内搜索 | 联系信箱 | -->
 您目前的位置:首页 > 自由软件 > 技术交流 > 应用编程 -->


    

蓝森林 http://www.lslnet.com 2006年8月16日 14:08

动态分配的内存不释放,程序退出后是否还在占据?

LINUX能否自动清理应用程序留下的垃圾内存?


tinybit,喜欢shell编程。http://tinybit.163.nethttp://tinybit.oso.com.cn


Re: 动态分配的内存不释放,程序退出后是否还在占据?

Memory will be release when the program exit



非常感谢! 但是哪里有这方面的声明或者怎么证明呢?

非常感谢! 但是哪里有这方面的声明或者怎么证明呢?


tinybit,喜欢shell编程。http://tinybit.163.nethttp://tinybit.oso.com.cn


Re: 非常感谢! 但是哪里有这方面的声明或者怎么证明呢?

os



Re: 非常感谢! 但是哪里有这方面的声明或者怎么证明呢?

Because the process itself has an independent virtual memory segment. the pointer in a process points to the virtual memory, not the physical memory. So when a process ends, the *whole* virtual memory will be expired, as well as the allocated memory block. The kernel does NOT actually *free* the memory for you, but discard the virtual memory so that it can be used for other potential consumers.






谢!!但是我编程序可以不用释放内存了----如果是很少的内存?

另外, DOS/WINDOWS是否在程序结束时有同样的效应? 有鉴于WINDOWS也使用虚拟内存.

tinybit,喜欢shell编程。http://tinybit.163.nethttp://tinybit.oso.com.cn


我不明白你为什么不想释放内存

如果你的程序要整天不停的运行,你最好释放,否则系统资源会越来越少。当然,如果你一次申请一大块内存,就算你使用free,系统的资源仍然会少。

人类每天都在干些什么?
--制造垃圾。

Re: 我不明白你为什么不想释放内存

我不是不想释放----我编程序一向严谨,丝毫不差! 我的程序段,从来都是正确的释放内存的.
但是------

我曾经尝试改造过 BASH, 我所改造的那些部分做完了以后, 发现 BASH 的其余部分,编程
似乎很混乱,也似乎觉得有不释放内存的代码段-----不过,那些动态内存是启动时分配一次,
分配的动作不在一个循环中,数量不大,不会造成很大危害.-------由于我不能肯定是否真的
没有正确释放,我还自编了一个故意不释放内存的测试程序,用FREE命令检验,也得不出结果,
所以就来这里发帖子了.
BASH的那些代码很大,要检查很不容易.动态内存果真在程序退出后自动销毁的话,我也就不用
费力去检验了,而把精力用在其它编程课题上.

谢谢几位的答复.



tinybit,喜欢shell编程。http://tinybit.163.nethttp://tinybit.oso.com.cn


Re: 我不明白你为什么不想释放内存

i've heard that some tools can parse your program and help you to find the memory leak... (damn, forgot its name, let me check and post again) [ejiang might know]





Re: 我不明白你为什么不想释放内存

谢谢! 但我想恐怕不太容易做到, 因为BASH有很多目录, 使用MAKE来管理编译,而且,
编程风格乱七八糟(很多人共同的作品).



tinybit,喜欢shell编程。http://tinybit.163.nethttp://tinybit.oso.com.cn


Re: 我不明白你为什么不想释放内存

ElectricFence, ccmalloc, LeakTrace are tools avaiable for memory leak detection.



3x!

我暂且记下,用到时再找你。

tinybit,喜欢shell编程。http://tinybit.163.nethttp://tinybit.oso.com.cn


Not entirely correct

The first one, ElectricFence, deals with another type of memory errors, i.e. invalid
memory access, but not memory leaks.

For the third one, I assume you were actually talking about LeakTracer. It does not
handle malloc, thus can not be used for C programs.

Actually if you ask any experienced Unix C/C++ programmer, he/she will tell you
that the best of such kind tool, which often called memory profiler, is "Purify".
Unfortunately "Purify" is a commertial software. Among the free altenatives of
"Purify", the ones better known are: GNU checker, dmalloc and memprof.



what about memleak-deluxe?

听说过,没见过,能用吗?

人类每天都在干些什么?
--制造垃圾。

memleak-deluxe, Hah?

Sorry never heard of. But I know that memleak is a tool used internally in XFree86
project and have been ported into several standalone tools. So this may be another
port.



感谢以上各位提供线索!(NULL)

.

tinybit,喜欢shell编程。http://tinybit.163.nethttp://tinybit.oso.com.cn




Copyright © 1999-2000 LSLNET.COM. All rights reserved. 蓝森林网站 版权所有。 E-mail : webmaster@lslnet.com