On Tue, Feb 5, 2019 at 4:11 PM Dennis Birkholz <p...@dennis.birkholz.biz>
wrote:

> Hi Joe,
>
> On 02.02.19 09:35, Joe Watkins wrote:
> > Some time ago I brought this up for discussion, and last night was
> reminded
> > of it's existence, and so this morning rebased and reworked the patch a
> > little based on the feedback I got back then.
> >
> > Since it was long ago, and there's no particular rush, I don't intend to
> > open voting until the current policy adjustment RFC's are resolved, but
> > wanted to give everyone a heads up and ask for any feedback you may have
> at
> > this time.
>
> thanks for proposing to bring weak references into core, I myself would
> have needed them once or twice.
>
> One point from the RFC bothers me:
>
> > The proposed API:
> > - does not support serialization
>
> That is a really unfortunate decision, I would really like to have them
> serializable. Otherwise if you want to persist a weak ref you always
> have to convert them to a real ref before serialization and back
> afterwards. I would really like to have this transparency build in.
> Would be great if that could be added.
>

Serialization for weak refs is a bit tricky, and I feel like supporting it
could easily become a foot-gun. The fundamental problem is that for
serialization to produce a meaningful value, the object referenced by a
WeakReference must also be part of the serialized object graph as a strong
reference somewhere. Otherwise, the WeakReference will immediately turn
into a dud when unserialization ends, because the object it references is
no longer live.

I think from a technical perspective, supporting serialization should be
possible and not overly hard, it's more a question of whether we want to.
As another data point, Java does not support serialization for
WeakReference.

Nikita

Reply via email to