6 Replies Latest reply on Apr 5, 2010 6:37 PM by jschellSomeoneStoleMyAlias

    Huge difference between used and commited bytes is a leak?

    843798
      Hi all,

      My environment:
      Java version: 1.6 U18 SE
      OS: Windows XP 32 bit

      I have a java client program which performs huge operation with a server. It basically gets a large string data form the server. After performing the operation I saw it (using task manager's Mem Usage) consuming 237MB. When I attached the program in Jconsole, it showing used bytes as 48MB and commited memory as 201MB for heap.

      I dint understand why such a huge difference exists between used and commited bytes. Is it a memory leak?
      How to understand the difference between them?
      Is possible to bring down the total memory consumption near to used bytes (i.e. 48MB)?

      -Hari
        • 1. Re: Huge difference between used and commited bytes is a leak?
          791266
          haki2 wrote:
          Hi all,

          My environment:
          Java version: 1.6 U18 SE
          OS: Windows XP 32 bit

          I have a java client program which performs huge operation with a server. It basically gets a large string data form the server. After performing the operation I saw it (using task manager's Mem Usage) consuming 237MB. When I attached the program in Jconsole, it showing used bytes as 48MB and commited memory as 201MB for heap.

          I dint understand why such a huge difference exists between used and commited bytes. Is it a memory leak?
          How to understand the difference between them?
          Is possible to bring down the total memory consumption near to used bytes (i.e. 48MB)?

          -Hari
          Hi,

          It's not a bug, the VM allocates memory from the OS, but it does currently not release memory back to the OS, it's designed to work like that, and the reserved memory is the managed by the VM.

          The javadoc for MemoryUsage explains a bit about it:
          [http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/MemoryUsage.html]
          • 2. Re: Huge difference between used and commited bytes is a leak?
            843798
            kajbj wrote:
            It's not a bug, the VM allocates memory from the OS, but it does currently not release memory back to the O
            That's not entirely true, at least not according [to this article|http://docs.sun.com/source/819-0084/pt_tuningjava.html]:
            By default, the JVM grows or shrinks the heap at each GC to try to keep the proportion of free space to the living objects at each collection within a specific range. This range is set as a percentage by the parameters -XX:MinHeapFreeRatio=minimum and -XX:MaxHeapFreeRatio=maximum [...]
            (emphasis mine)

            This indicates that the JVM does indeed return memory to the OS on occasion.
            • 3. Re: Huge difference between used and commited bytes is a leak?
              791266
              JoachimSauer wrote:
              kajbj wrote:
              It's not a bug, the VM allocates memory from the OS, but it does currently not release memory back to the O
              That's not entirely true, at least not according [to this article|http://docs.sun.com/source/819-0084/pt_tuningjava.html]:
              By default, the JVM grows or shrinks the heap at each GC to try to keep the proportion of free space to the living objects at each collection within a specific range. This range is set as a percentage by the parameters -XX:MinHeapFreeRatio=minimum and -XX:MaxHeapFreeRatio=maximum [...]
              (emphasis mine)

              This indicates that the JVM does indeed return memory to the OS on occasion.
              Cool. You learn something new every day. I know that they previously never released memory back to the OS (except when the VM terminated) but they wanted to change it. I hadn't heard that it had been changed, and I have actually never seen it happen (but that does of course not mean that it can't happen)
              • 4. Re: Huge difference between used and commited bytes is a leak?
                843798
                Thanks all for the replies and special thanks to Joachim Sauer.

                I used -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=10 options for JVM and memory consumed is controlled. After using those options, JVM is consuming 110MB almost 127MB got released back to OS. Really cooool. :)

                Thanks
                Hari
                • 5. Re: Huge difference between used and commited bytes is a leak?
                  843798
                  haki2 wrote:
                  I used -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=10 options for JVM and memory consumed is controlled. After using those options, JVM is consuming 110MB almost 127MB got released back to OS. Really cooool. :)
                  That's perfect. Just be aware that you buy the reduced memory usage by increased CPU requirements, because the JVM will have to request/release memory more often. It's a classical CPU/memory trade-off.
                  • 6. Re: Huge difference between used and commited bytes is a leak?
                    jschellSomeoneStoleMyAlias
                    haki2 wrote:
                    I used -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=10 options for JVM and memory consumed is controlled. After using those options, JVM is consuming 110MB almost 127MB got released back to OS. Really cooool. :)
                    That is unlikely to be relevant.

                    If the VM is using the memory, that is it has live data, then it will have no impact because it can't return memory in use.
                    If the VM isn't using the memory and it was in use at one time then all that happens is that the OS swaps it to the hard drive.
                    If the VM isn't using the memory and it was never in use then the OS will have never committed it to the app anyways (it will not in fact exist.)

                    None of those cases will stop other applications from using memory in any way.