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

ObjectStreamClass caches keep ClassLoaders alive

    XMLWordPrintable

    Details

      Backports

        Description

        The caches in ObjectStreamClass basically map WeakReference<Class> to SoftReference<ObjectStreamClass>, where the ObjectStreamClass also references the same Class. That means that the cache entry, and thus the class and its class-loader, will not get reclaimed, unless the GC determines that memory pressure is very high.

        However, this seems bogus, because that unnecessarily keeps ClassLoaders and all its classes alive much longer than necessary: as soon as a ClassLoader (and all its classes) become unreachable, there is no point in retaining the stuff in OSC's caches.

        This can be demonstrated by compiling the attached .java files, and run:
        java TestObjectStreamClass

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                rkennke Roman Kennke
                Reporter:
                rkennke Roman Kennke
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: