Weak & Soft references in Go

3,811 views
Skip to first unread message

Anatol Pomozov

unread,
Mar 5, 2010, 3:17:01 PM3/5/10
to golang-nuts
Hi,

Is there anything that is similar to Soft & Weak references* in java?
I found it very useful for creating unbound caches.

cache := make(map[string] string);

I wish to have cache that is cleaned by GC automatically when nobody
references its key/values

*) http://weblogs.java.net/blog/enicholas/archive/2006/05/understanding_w.html

Russ Cox

unread,
Mar 5, 2010, 3:34:18 PM3/5/10
to Anatol Pomozov, golang-nuts
> Is there anything that is similar to Soft & Weak references* in java?

Not really, no.

Russ

righ...@gmail.com

unread,
Feb 26, 2015, 11:29:21 AM2/26/15
to golan...@googlegroups.com, anatol....@gmail.com, r...@golang.org
Is there a specific reason for this?

Ian Lance Taylor

unread,
Feb 26, 2015, 11:43:52 AM2/26/15
to righ...@gmail.com, golang-nuts
On Thu, Feb 26, 2015 at 1:08 AM, <righ...@gmail.com> wrote:
> Is there a specific reason for this?

Note that you are replying to a thread from almost five years ago.
For anything more than a few months I suggest that you start a new
thread rather than replying to an old one. You can always reference
the old thread in the archives if appropriate.

As far as I've ever been able to see, weak references are isomorphic
to finalizers, and we have finalizers
(http://golang.org/pkg/runtime/#SetFinalizer). Finalizers seem easier
to reason about, easier to implement, and the limitations are more
clear. So it seems to me that we are OK.

Ian


> On Friday, 5 March 2010 21:34:18 UTC+1, Russ Cox wrote:
>>
>> > Is there anything that is similar to Soft & Weak references* in java?
>>
>> Not really, no.
>>
>> Russ
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages