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

Synchronizer timed acquire still leaks memory

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 5.0, 6
    • core-libs
    • b06
    • generic, x86
    • generic, linux, windows_2003, windows_xp
    • Verified

        Continually looping on an unavailable semaphore,
        for example, with a timed tryAcquire, continues to consume memory.

        ------------------------------------
        public class Leak6 {
            public static void main(String [] args) throws Throwable {
            final int n = 1000*1000;

            long mem = Runtime.getRuntime().freeMemory();
            System.out.println("Free: " + mem);

            Semaphore s = new Semaphore(0);
            int i = 0;
            try {
                while (++i < n)
                s.tryAcquire(1,TimeUnit.MICROSECONDS);
            } catch (OutOfMemoryError oome) {
                System.out.printf("OOME on iteration %d%n", i);
            }

            System.gc();
            long mem2 = Runtime.getRuntime().freeMemory();
            System.out.println("Memory used: " + (mem2 - mem));
            }
        }
        ------------------------------------
        ==> java -Xmx16m -esa -ea Leak6
        Free: 7675240
        OOME on iteration 488232
        Memory used: 5888064

              martin Martin Buchholz
              martin Martin Buchholz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: