要在程序里着手,看是否最优化。
http://www.onjava.com/lpt/a//onjava/2001/05/30/optimization.html
http://www.onjava.com/lpt/a//onjava/2001/05/30/optimization.html
解决方案 »
- 为什么Vector 在集合中保存大量的数据那比ArrayList更有优势?
- 想问大神们几个问题
- JAVA通过ODBC,连接到ACCESS上,哪位大哥,写个源码。谢谢
- 有关HashEntry的一个问题
- 如何动态创建对象
- 真郁闷
- 3个月的java基础知识,我够资格学习网络部分的知识了吗?
- 为什么老是java.lang.NullPointerException
- 用jbuilder7打包生成可执行文件后出错,急!!
- 哪里可以下载到JDK的源代码?
- serversocket.accept().getOutputStream() 服务器最多能够维持多少个OutputStream?
- 请问那位大哥大姐有关于JAVA语言实现的资料
most obvious example would be:
obj = new XXX();
vector.add(obj);
obj = null;//here, obj won't be gc'ed because it is still in vector.
内存泄漏主要存在于极个别awt重量组件,但也不是全部
what it does is just say :"hey, I'm concerned about the memory, could you please check if you can collect any object for me?"
But, jvm does not guarantee to do anything for you. It may say:"I'm sorry, but I don't see any necessity to do that now."tainy_zhang:
if you like, you can post some suspicious code, so that we can find more clue.
我用optimizeit和purify都进行了测试,在打开一个窗口之前和关闭一个窗口之后都利用工具提供的gc进行了垃圾清除,可以发现系统的确做了gc,因为free memeory增加了,可是,针对某些窗口的测试表明,这个窗口在开关一次后,分配的内存总是有一个固定数量不能被回收,比如每次都是500k左右,所以我觉得是内存泄露。
在solaris上运行的时候,可以观察free mem在持续下降,并且有时会导致GUI灰掉并且不可用,这个问题非常严重,所以特别急切的希望大家的帮助,谢谢!!about the code:we develop large app,so I think it is impossible for you to read the whole code.but piece of it show nothing,I think.thanks anyway
the gc is most unlikely to have a bug.
some gui api may have problem though.some advices:
1. gc() does not help. if you find memory leak, go find the reason. gc() will not do any good to it.
2. investigate your code. for things like
{
Object obj = ...;
somefunction(obj);
}
//obj may not be collected by gc here
3.
{
String s = get_a_big_string()
String s2 = s.substring(i, j);
somefunc(s2);
}
//here, s will not be collected until s2 is collected.
4. some async image api may require substantial memory, but takes time to release it. if you keep calling async image api, you may run out of memory. (this is not called memory leak though).
By the way,the most serious thing is not the memory leak,but the app Gui may become gray and unuseable on Solaris running under JRE1.2.2 which will not happen under win2000.
For some reason,we developped the app using 1.3.1,but have to compile and run it under 1.2.2 now;-(.Do you know why the app will turn gray?