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

Serious memory leak with WeakReference objects

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.4.0
    • hotspot
    • None
    • gc
    • x86
    • windows_nt

      I would like to migrate our code away from Finalizers and use PhantomReference
      objects instead to take care of our problem of deleting native data associated
      with GC'd Java objects. However, when I converted some of our code to use
      Phantom (or Weak) references, I discovered that the int[] objects I was creating
      (and then reference in native code via GlobalWeakRef) were only sometimes
      getting GC'd.

      Since these buffers consume up to several hundred K per object (some apps
      allocate new back buffers per frame, which ends up creating one of these
      kinds of arrays per frame), this leak soon causes an app to run out of
      memory in the java heap and crash.

      I have attached a self-contained example of the problem. The class
      hierarchy in the example mimics the hierarchy of classes in our application,
      just as it mimics the problems we are seeing with memory leaks.

      To run the example, type:
      java NativeArrayReferencesTest
      The application will print out messages when objects are GC'd and will
      eventually print an OutOfMemoryError.

            Unassigned Unassigned
            chaasesunw Chet Haase (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: