java xmx内存分配,Java使用的内存远远多于使用-Xmx分配的内存

I have a project I'm writing (in Java) for a class where the prof says we're not allowed to use more than 200m

I limit the stack memory to 50m (just to be absolutely sure) with -Xmx50m but according to top, it's still using 300m

I tried running Eclipse Memory Analyzer and it reports only 26m

Could this all be memory on the stack?, I'm pretty sure I never go further than about 300 method calls deep (yes, it is a recursive DFS search), so that would have to mean every stack frame is using up almost a megabyte which seems hard to believe.

The program is single-threaded. Does anyone know any other places in which I might reduce memory usage? Also, how can I check/limit how much memory the stack is using?

UPDATE: I'm using the following JVM options now with no effect (still about 300m according to top): -Xss104k -Xms40m -Xmx40m -XX:MaxPermSize=1k

Another UPDATE: Actually, if I let it run a little bit longer (with all these options) about half the time it suddenly drops to 150m after 4 or 5 seconds (the other half it doesn't drop). What makes this really strange is that my program has no stochastic (and as I said it's single-threaded) so there's no reason it should behave differently on different runs

Could it have something to do with the JVM I'm using?

java version "1.6.0_27"

OpenJDK Runtime Environment (IcedTea6 1.12.3) (6b27-1.12.3-0ubuntu1~10.04)

OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

According to java -h, the default JVM is -server. I tried adding -cacao and now (with all the other options) it's only 59m. So I suppose this solves my problem. Can anyone explain why this was necessary? Also, are there any drawbacks I should know about?

One more update: cacao is really really slow compared to server. This is an awful option

解决方案

Top command reflects the total amount of memory used by the Java application. This includes among other things:

A basic memory overhead of the JVM itself

the heap space (bounded with -Xmx)

The permanent generation space (-XX:MaxPermSize - not standard in all JVMs)

threads stack space (-Xss per stack) which may grow significantly depending on the number of threads

Space used by native allocations (using ByteBufer class, or JNI)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值