tomcat+mysql连接池使用的时候内存不释放????

05-01-04 yangbc
我用tomcat+mysql连接池,在jsp中使用插入和显示来操作,按住F5刷新,
可以看到tomcat进程使用内存狂涨,如果一下一下点击刷新按钮,内存不会狂涨。狂涨之后tomcat却不释放内存,这是为什么阿?
难道tomcat只适合开发就是指性能不行这个原因么?不是说Java有内存回收机制么,我用优化大师看了一下,tomcat占用的内存好像大多是jvm.dll这个调用产生的,这是不是说明虚拟机没有释放工作时占用的内存,那这样是不是也说明java的内存回收机制有问题?

百思不得其解阿

tomcat在开始的时候只占用25兆内存,现在占到了50兆,而且过了一天,没有任何释放的意思。

各位牛人,发表以下看法阿,我感觉别的jsp容器也不见得没有这个问题吧

yangbc
2005-01-04 11:24
说明一下:我的jsp中插入显示的java部分在操作后已经用了conn.close()了,不应该是代码的原因。

dabb
2005-01-04 15:03
你看到的是jvm占用的max 内存大小,进程占用的内存大小在所设置的jvm heap max size范围内增长是正常的。对于该进程实际正在使用的heap大小可以通过打印jvm垃圾回收信息查看(vergbose:gc)

xiayaazinabu
2005-01-05 13:30
你是不是使用tomcat的默认数据库连接池,那个基本上是没用的,

另外关于jvm的垃圾收集机制,为了不给性能带来影响,它是很懒的,基本上是不会自动释放内存的,

除非可用内存很小的情况下,所以有些资源要自己释放.

rasclewen
2005-01-06 15:44
我也碰到这个问题。
我的是jboss+ms sqlserver,实际上也就是tomcat5+ms sqlserver

有个方法用连接池来读取数据
public Vectir getDatas() {

//从数据库中读出数据
conn.close(); //在finally
}

测试如有如下操作时:
for (int i=0;i<20;i++) {
getDatas()
}
就会发现和楼主同样的问题。

rasclewen
2005-01-06 15:55
然后出现以下错误:
15:51:25,140 INFO [STDOUT] at org.apache.jsp.company_005fnewadd_005ftemplat
e_005f1_jsp._jspService(company_005fnewadd_005ftemplate_005f1_jsp.java:74)
15:51:25,140 INFO [STDOUT] at org.apache.jasper.runtime.HttpJspBase.service
(HttpJspBase.java:94)
15:51:25,140 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:810)
15:51:25,140 INFO [STDOUT] at org.apache.jasper.servlet.JspServletWrapper.s
ervice(JspServletWrapper.java:324)
15:51:25,140 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.serviceJ
spFile(JspServlet.java:292)
15:51:25,140 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.service(
JspServlet.java:236)
15:51:25,140 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:810)
15:51:25,140 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:237)
15:51:25,140 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:157)
15:51:25,140 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatche
r.invoke(ApplicationDispatcher.java:704)
15:51:25,140 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatche
r.doInclude(ApplicationDispatcher.java:590)
15:51:25,140 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatche
r.include(ApplicationDispatcher.java:510)
15:51:25,140 INFO [STDOUT] at org.apache.jasper.runtime.JspRuntimeLibrary.i
nclude(JspRuntimeLibrary.java:966)
15:51:25,140 INFO [STDOUT] at org.apache.jsp.index_jsp._jspService(index_js
p.java:164)
15:51:25,156 INFO [STDOUT] at org.apache.jasper.runtime.HttpJspBase.service
(HttpJspBase.java:94)
15:51:25,156 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:810)
15:51:25,156 INFO [STDOUT] at org.apache.jasper.servlet.JspServletWrapper.s
ervice(JspServletWrapper.java:324)
15:51:25,156 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.serviceJ
spFile(JspServlet.java:292)
15:51:25,156 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.service(
JspServlet.java:236)
15:51:25,156 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:810)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:237)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:157)
15:51:25,156 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilte
r.doFilter(ReplyHeaderFilter.java:75)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:186)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:157)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve
.invoke(StandardWrapperValve.java:214)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:104)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.inv
oke(StandardPipeline.java:520)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve
.invokeInternal(StandardContextValve.java:198)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve
.invoke(StandardContextValve.java:152)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:104)
15:51:25,156 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipal
Valve.invoke(CustomPrincipalValve.java:66)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:102)
15:51:25,156 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssocia
tionValve.invoke(SecurityAssociationValve.java:158)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:102)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.inv
oke(StandardPipeline.java:520)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.in
voke(StandardHostValve.java:137)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:104)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.i
nvoke(ErrorReportValve.java:118)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:102)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.inv
oke(StandardPipeline.java:520)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.
invoke(StandardEngineValve.java:109)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:104)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.inv
oke(StandardPipeline.java:520)
15:51:25,156 INFO [STDOUT] at org.apache.catalina.core.ContainerBase.invoke
(ContainerBase.java:929)
15:51:25,156 INFO [STDOUT] at org.apache.coyote.tomcat5.CoyoteAdapter.servi
ce(CoyoteAdapter.java:160)
15:51:25,156 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.proc
ess(Http11Processor.java:799)
15:51:25,156 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http1
1ConnectionHandler.processConnection(Http11Protocol.java:705)
15:51:25,156 INFO [STDOUT] at org.apache.tomcat.util.net.TcpWorkerThread.ru
nIt(PoolTcpEndpoint.java:577)
15:51:25,156 INFO [STDOUT] at org.apache.tomcat.util.threads.ThreadPool$Con
trolRunnable.run(ThreadPool.java:683)
15:51:25,156 INFO [STDOUT] at java.lang.Thread.run(Thread.java:534)
15:51:25,687 INFO [STDOUT] ConnectionPool: Connection closed unexpectedly
15:51:27,687 INFO [STDOUT] ConnectionPool: Connection closed unexpectedly
15:51:27,687 INFO [STDOUT] ConnectionPool: Connection closed unexpectedly
15:51:27,687 INFO [STDOUT] ConnectionPool: Connection closed unexpectedly
15:51:27,687 INFO [STDOUT] ConnectionPool: Connection closed unexpectedly
15:51:27,687 INFO [STDOUT] ConnectionPool: Connection closed unexpectedly
15:51:27,687 INFO [STDOUT] ConnectionPool: Connection closed unexpectedly
15:51:27,687 INFO [STDOUT] ConnectionPool: Connection closed unexpectedly
15:51:27,687 INFO [STDOUT] ConnectionPool: Connection closed unexpectedly
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x77F
88216
Function=RtlpWaitForCriticalSection+0x60
Library=C:\WINNT\system32\ntdll.dll

Current Java thread:
at sun.jdbc.odbc.JdbcOdbc.freeStmt(Native Method)
at sun.jdbc.odbc.JdbcOdbc.SQLFreeStmt(JdbcOdbc.java:3392)
- locked <0x11a9ccb8> (a sun.jdbc.odbc.JdbcOdbc)
at sun.jdbc.odbc.JdbcOdbcStatement.reset(JdbcOdbcStatement.java:526)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedState
ment.java:209)
- locked <0x12fb8a80> (a sun.jdbc.odbc.JdbcOdbcPreparedStatement)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(JdbcOdbcPrepared
Statement.java:89)
at sitt.admin.module.ModuleBean.getAllModuleList(ModuleBean.java:33)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:61)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
92)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
lter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(Standard
ContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrinc
ipalValve.java:66)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
yAssociationValve.java:158)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:16
0)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:683)
at java.lang.Thread.run(Thread.java:534)

Dynamic libraries:
0x00400000 - 0x0040B000 c:\j2sdk1.4.2\bin\java.exe
0x77F80000 - 0x77FFD000 C:\WINNT\system32\ntdll.dll
0x796D0000 - 0x79732000 C:\WINNT\system32\ADVAPI32.dll
0x77E60000 - 0x77F32000 C:\WINNT\system32\KERNEL32.DLL
0x786F0000 - 0x78761000 C:\WINNT\system32\RPCRT4.DLL
0x78000000 - 0x78045000 C:\WINNT\system32\MSVCRT.dll
0x08000000 - 0x08139000 c:\j2sdk1.4.2\jre\bin\client\jvm.dll
0x77DF0000 - 0x77E55000 C:\WINNT\system32\USER32.dll
0x77F40000 - 0x77F7B000 C:\WINNT\system32\GDI32.DLL
0x77530000 - 0x77560000 C:\WINNT\system32\WINMM.dll
0x75E00000 - 0x75E1A000 C:\WINNT\system32\IMM32.DLL
0x6C330000 - 0x6C338000 C:\WINNT\system32\LPK.DLL
0x65D20000 - 0x65D74000 C:\WINNT\system32\USP10.dll
0x10000000 - 0x10007000 c:\j2sdk1.4.2\jre\bin\hpi.dll
0x007D0000 - 0x007DE000 c:\j2sdk1.4.2\jre\bin\verify.dll
0x007E0000 - 0x007F9000 c:\j2sdk1.4.2\jre\bin\java.dll
0x00800000 - 0x0080D000 c:\j2sdk1.4.2\jre\bin\zip.dll
0x188B0000 - 0x188BF000 C:\j2sdk1.4.2\jre\bin\net.dll
0x74FB0000 - 0x74FC4000 C:\WINNT\system32\WS2_32.dll
0x74FA0000 - 0x74FA8000 C:\WINNT\system32\WS2HELP.DLL
0x77800000 - 0x7780C000 C:\WINNT\System32\rnr20.dll
0x77960000 - 0x77984000 C:\WINNT\system32\DNSAPI.DLL
0x74FD0000 - 0x74FDA000 C:\WINNT\system32\WSOCK32.DLL
0x77300000 - 0x77313000 C:\WINNT\system32\iphlpapi.dll
0x774E0000 - 0x774E5000 C:\WINNT\system32\ICMP.DLL
0x772E0000 - 0x772F7000 C:\WINNT\system32\MPRAPI.DLL
0x750E0000 - 0x750EF000 C:\WINNT\system32\SAMLIB.DLL
0x75100000 - 0x7514F000 C:\WINNT\system32\NETAPI32.DLL
0x797B0000 - 0x797BF000 C:\WINNT\system32\Secur32.dll
0x77BD0000 - 0x77BE1000 C:\WINNT\system32\NTDSAPI.dll
0x77930000 - 0x7795A000 C:\WINNT\system32\WLDAP32.DLL
0x75150000 - 0x75156000 C:\WINNT\system32\NETRAP.dll
0x77A30000 - 0x77B1F000 C:\WINNT\system32\OLE32.DLL
0x77990000 - 0x77A2B000 C:\WINNT\system32\OLEAUT32.DLL
0x77370000 - 0x7739F000 C:\WINNT\system32\ACTIVEDS.DLL
0x77340000 - 0x77363000 C:\WINNT\system32\ADSLDPC.DLL
0x777F0000 - 0x777FE000 C:\WINNT\system32\RTUTILS.DLL
0x6D990000 - 0x6DA3C000 C:\WINNT\system32\SETUPAPI.DLL
0x794D0000 - 0x79531000 C:\WINNT\system32\USERENV.DLL
0x774A0000 - 0x774D3000 C:\WINNT\system32\RASAPI32.DLL
0x77480000 - 0x77491000 C:\WINNT\system32\RASMAN.DLL
0x774F0000 - 0x77512000 C:\WINNT\system32\TAPI32.DLL
0x71710000 - 0x71794000 C:\WINNT\system32\COMCTL32.DLL
0x188C0000 - 0x18929000 C:\WINNT\system32\SHLWAPI.DLL
0x77320000 - 0x77339000 C:\WINNT\system32\DHCPCSVC.DLL
0x777A0000 - 0x777A8000 C:\WINNT\System32\winrnr.dll
0x777B0000 - 0x777B5000 C:\WINNT\system32\rasadhlp.dll
0x74F50000 - 0x74F6E000 C:\WINNT\system32\msafd.dll
0x74F90000 - 0x74F97000 C:\WINNT\System32\wshtcpip.dll
0x19840000 - 0x19848000 C:\j2sdk1.4.2\jre\bin\nio.dll
0x1A350000 - 0x1A35C000 C:\j2sdk1.4.2\jre\bin\JdbcOdbc.dll
0x1F7C0000 - 0x1F7F4000 C:\WINNT\system32\ODBC32.dll
0x76AF0000 - 0x76B2E000 C:\WINNT\system32\comdlg32.dll
0x78F90000 - 0x791D5000 C:\WINNT\system32\SHELL32.DLL
0x1A460000 - 0x1A476000 C:\WINNT\system32\odbcint.dll
0x777E0000 - 0x777E7000 C:\WINNT\system32\VERSION.dll
0x75950000 - 0x75956000 C:\WINNT\system32\LZ32.DLL
0x1F810000 - 0x1F82A000 C:\WINNT\system32\odbccp32.dll
0x75490000 - 0x75494000 C:\WINNT\system32\security.dll
0x782D0000 - 0x782F1000 C:\WINNT\system32\msv1_0.dll
0x79C40000 - 0x79CC7000 C:\WINNT\system32\CRYPT32.DLL
0x773F0000 - 0x77400000 C:\WINNT\system32\MSASN1.DLL
0x1A480000 - 0x1A592000 C:\j2sdk1.4.2\jre\bin\awt.dll
0x777C0000 - 0x777DE000 C:\WINNT\system32\WINSPOOL.DRV
0x79B20000 - 0x79B30000 C:\WINNT\system32\MPR.DLL
0x1A5A0000 - 0x1A5F1000 C:\j2sdk1.4.2\jre\bin\fontmanager.dll
0x1A650000 - 0x1A673000 C:\j2sdk1.4.2\jre\bin\cmm.dll
0x1A780000 - 0x1A79E000 C:\j2sdk1.4.2\jre\bin\jpeg.dll
0x41230000 - 0x412AF000 C:\WINNT\System32\sqlsrv32.dll
0x41100000 - 0x4110C000 C:\WINNT\System32\SQLWOA.dll
0x76940000 - 0x76947000 C:\WINNT\system32\NDDEAPI.DLL
0x73330000 - 0x73337000 C:\WINNT\system32\DBMSSOCN.DLL
0x77900000 - 0x77923000 C:\WINNT\system32\imagehlp.dll
0x72960000 - 0x7298D000 C:\WINNT\system32\DBGHELP.dll
0x687E0000 - 0x687EB000 C:\WINNT\system32\PSAPI.DLL

Heap at VM Abort:
Heap
def new generation total 4096K, used 1693K [0x10010000, 0x10480000, 0x104f000
0)
eden space 3648K, 34% used [0x10010000, 0x101488e8, 0x103a0000)
from space 448K, 98% used [0x103a0000, 0x1040ec50, 0x10410000)
to space 448K, 0% used [0x10410000, 0x10410000, 0x10480000)
tenured generation total 53400K, used 44752K [0x104f0000, 0x13916000, 0x14010
000)
the space 53400K, 83% used [0x104f0000, 0x130a43a0, 0x130a4400, 0x13916000)
compacting perm gen total 20736K, used 20601K [0x14010000, 0x15450000, 0x18010
000)
the space 20736K, 99% used [0x14010000, 0x1542e440, 0x1542e600, 0x15450000)

Local Time = Thu Jan 06 15:51:32 2005
Elapsed Time = 16640
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2_06-b03 mixed mode)
#
# An error report file has been saved as hs_err_pid2288.log.
# Please refer to the file for further information.
#
请按任意键继续 . . .

rasclewen
2005-01-06 15:58
那位高人指点指点????

xiayaazinabu
2005-01-07 08:04
你是使用jdbc:odbc桥把,

你有没有在你本机上配置一个文件或者系统数据源

rasclewen
2005-01-07 08:50
有呀!!
而且这种情况在连续按F5刷新的时候才会出现,正常使用是没有问题的。
真的不知道是这么回事?

我昨天安装了weblogic6.1来测试,就没有这种问题,真的不知道了呀。

layout
2005-01-07 10:19
很正常啊,你看到的50M是tomcat占用的总的内存,其实也就是jvm的内存量.jvm的最大内存可能会到1.5G(你自己要设置),而且和你的内存回收机制有关系的.
内存回收并不是把释放的资源的内存还给系统,而是还给了jvm.jvm里面分段,有free,old,new等不同的段,如果free的用完了,而old的还没有按照jvm的释放算法释放就会继续向系统申请内存,直到到达最大jvm可用内存为止(如果到了最大内存仍然不能释放old段,而还有新的请求到达,这时候会报告outofmemory错误).old段的内存释放以后放回free的段里面,所以总的内存量一般来说都是往上升的,并且很少jvm的使用内存能够释放到初始设置(因为向系统请求内存的效率源源小于jvm内部分配内存)

此外,检查系统是否有内存泄漏并不只是检查connection是否被关闭了,你可以使用borland的Optimizeit来看看jvm里面到底什么对象占用了内存.如果发现这个占用内存的对象数量不断增加(每次刷新都会增加一些)的话,可能就是在处理那个对象的时候没有释放内存(如果你的程序没有取消对某个对象的引用,jvm并不会去回收该对象的内存数量).

希望对您有所帮助.

dabb
2005-01-07 10:24
说了没有问题就是没有问题了,有问题那也是你自己程序的问题。你就是写一个最简单的单纯操作内存的jsp(操作memory块要比较大一点,以便更明显的反映问题),然后用jmeter,loadrunner之类的负载测试工具让他不停的运行,它也会使你的进程站用的memory不挺的增加。当然你的jvm进程占用的内存大小会限制在你设置的最大jvm heap 大小+程序本身占用的内存之内。但这只是表面上的数据,通过打印垃圾回收容余信息(jvm 参数-verbose:gc),可以看到实际程序占用的内存大小,如GC 417813K->154877K(753664K),说明现在使用的heap大小为154877k,而最大jvm heap大小是753664k,这括号里的值就是你通过进程工具看到的进程占用的值-程序本身占用的内存。jvm只是逻辑上占用这块753664k内存,实际上用到的只有154877k。
当然如果你的最大堆大小设置过小(对于你的应用程序),就会出现out of memory 出错。jvm还有各种其它的相关参数,比如newSize ,SurvivorRatio等,这些值是关于heap中各个不同类别内存块的,主要是“新生代”和“保留代”的大小,还有一种是perm,用于存储永久数据(在jvm生存周期内)。

还有关于不同的垃圾回收器的参数,比如一般server型的应用程序使用copying(用于新生代minor collection),mark-compact(用于保留代major collection),这是默认值。而对于一些应用程序,比如象jmeter这样的,经常用于不间断的产生负载请求的程序,使用incremental类型的回收器(加参数-Xincgc)可能会更适合,因为incremental类型的回收器一次只回收一部分“保留代”内存,也就是major collection(这是最耗时的),而不是全部回收,就避免了程序因进行major collection中断过久,影响测试的真实性。


这些值在各种平台,各种版本的jvm中都可能不同,实际生产环境中适当调整这些参数都会提高应用程序的性能。

rasclewen
2005-01-07 17:01
恕小弟愚蠢,楼上两位所说的我还是不太明白。

那既然是如上所说,真正的问题到底在那里呢?如何解决呢?

再谢谢!!!

layout
2005-01-10 14:15
不明白?.....

内存上涨是很正常的现象,并不是你认为的系统错误或者不可接受(只要不是outofmemory).

如果你发现你的内存上涨的非常快或者有其他的现象推断出来内存泄漏的话就可以使用一些工具来分析内存对象到底是什么东西占用.