Java using up far more memory than allocated with -Xmx

前端 未结 5 1711
轻奢々
轻奢々 2020-12-25 11:45

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)

5条回答
  •  北海茫月
    2020-12-25 12:31

    With -Xmx you are configuring heap size. To configure stack size use -Xss parameter. Sum of those two parameters should be approximately what you want:

    -Xmx150m -Xss50m
    

    for example.

    Additionally there is also -XX:MaxPermSize parameter which controls. This parameter for -client has default value of 32mb and for -server 64mb. According to your configuration calculate it as well. PermGen space is:

    The permanent generation is used to hold reflective of the VM itself such as class objects and method objects.

    So basically it stores internal data of the JVM, like classes definitions and intern-ed strings.

    At the end I must say that there is one part which you can't control, that is memory used by native java process. Java is program, just like any other, so it uses memory also. If you are watching memory usage in Task Manager you will see this memory as well together with your program memory consumption.

提交回复
热议问题