Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6749531

ByteBuffer.allocateDirect is still causing OutOfMemoryErrors

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u10
    • core-libs
    • x86
    • windows_xp

      J2SE Version (please include all output from java -version flag):
      java version "1.6.0_07"
      Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
      Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

      Same thing for 6u10 RC2 release

      Does this problem occur on J2SE 5.0.x or 6.0? Yes / No (pick one)
      Yes

      Operating System Configuration Information (be specific):
      Microsoft Windows XP [Version 5.1.2600]

      Bug Description:
      ByteBuffer.allocateDirect is still causing OutOfMemoryErrors

      I found lots of Bug Reports with the same Test Case, each closed saying fixed in much earlier versions of Java (like 1.4).
      I still get the OutOfMemoryErrors every single time running on 1.6.0_07.

      Expected: The code below should run to completion as the code is never holding on to any of the ByteBuffers.

      >java -Xmx1g Test

      Actual: Allocation Size: 107039948
      0
      1
      2
      3
      4
      Exception in thread "main" java.lang.OutOfMemoryError
              at sun.misc.Unsafe.allocateMemory(Native Method)
              at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:99)
              at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)
              at Test.main(Test.java:9)


      import static java.lang.System.*;
      import static java.nio.ByteBuffer.*;

      public class Test {
        public static void main(String[] args) {
          int allocationSize = (int)(Runtime.getRuntime().maxMemory() / 10);
          out.println("Allocation Size: " + allocationSize);
          for (int i = 0; i < 10000; i++) {
            allocateDirect(allocationSize);
            out.println(i);
          }
        }
      }

            Unassigned Unassigned
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: