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

Not clear: Serialization of WeakReferences

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs
    • generic
    • generic



      Name: dbT83986 Date: 03/04/99


      I suppose the documentation on serialization is not aware
      about the new java.lang.ref.* classes, e.g. WeakReference.
      Another possibility: You simply didn't define a nice solution
      for getting *small* object streams.

      The online doc says (for ObjectOutputStream):
      "The default serialization mechanism for an object writes the class of the object, the class signature, and the values of all
      non-transient and non-static fields. References to other objects (except in transient or static fields) cause those objects to
      be written also. Multiple references to a single object are encoded using a reference sharing mechanism so that graphs of
      objects can be restored to the same shape as when the original was written."

      This would mean that objects I regard as not important
      would be serialized (they may be garbage collected at any time,
      when my "master object" only holds a soft reference to it but
      nobody else has a hard link to them).

      I suppose a much cleaner definition would be to define that
      serializing WeakReference objects leads to their inner reference
      set to null. This would be a clean definition AND even better
      means that my object streams get pretty small. When I like those
      referenced objects to serialized I must have an object
      that has hard links to them anyway.

      This could be a nice solution for the problem of accidentially
      serializing e.g. propertyChangeListeners, too. Those listeners
      normally only need to be weakly referenced. When serialization
      reaches a WeakReference, it simply could set the referent to
      null and stop further traversion of the object graph at this
      point. This change would make serialization "proxy aware".
      (Review ID: 54597)
      ======================================================================

            mr Mark Reinhold
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: