Talk:Weak reference

message: It would be nice to include a description of Java's phantom and soft references here. -- Doug Bell (talk/contrib) 11:29, 13 January 2006 (UTC)
replies: text: Done ... with links to their own articles. Stumps 00:05, 7 February 2007 (UTC)
replies: text: I don't think that the part that says "Another use of weak references is in writing a cache." should be there: soft references should be used for that purpose (because they are defined to take memory pressure into account, which is normally what you want for a cache). Nicolas Barbier (talk) 17:10, 14 December 2010 (UTC)

message: Currently, this article uses this Java example:
import java.lang.ref.WeakReference;
public class ReferenceTest {
	public static void main(String[] args) throws InterruptedException {
            WeakReference r = new WeakReference(new String("I'm here"));
            WeakReference sr = new WeakReference("I'm here");
            System.out.println("before gc: r=" + r.get() + ", static=" + sr.get());
            System.gc();
            Thread.sleep(100);
            // only r.get() becomes null
            System.out.println("after gc: r=" + r.get() + ", static=" + sr.get());
	}
}
In my opinion, this example doesn't clarify the topic at hand, but instead raises new questions.
*Why is it that r's String gets garbage-collected, but sr's String does not? Is this because of string interning? (new String("I'm here") versus "I'm here")
*What happens when garbage collection spuriously kicks in concurrently right after the first line? Would this make the first println statement already return r=null? 
*If weak references can be garbage collected, is there the danger of having a weak reference be garbage collected right after the moment it was created - already rendering the object useless before any sensible computation with this object took place?
*Is the WeakReference class the only way of creating weak references in a Java JVM environment?
--Abdull (talk) 23:00, 10 December 2012 (UTC)
thread_title:  Java example 

message: The article contained this text:
:Java was the first main language to introduce strong reference as the default object reference. Previously (ANSI) C only had weak references. However it was noted by David Hostettler Wain and Scott Alexander Nesmith that event trees were not evaporating properly. Thus strong/weak references of counted and uncounted references was derived (~1998).
I can’t make head or tail of this.  I don’t know what a “main language” might be, Java from 1996 has the same kind of strong references Lisp had in 1959, C doesn’t have references at all, I don’t know who these Wain and Nesmith guys are, I don’t know what event trees are or why they might evaporate or what that has to do with weak references.  I suspect this text may have been translated from a Chinese Wikipedia article but not so well that I can figure out what it’s saying.  I tried to find the Wain & Nesmith 1998 text that is alluded to, but without success.
Feel free to re-add what this text was trying to say.  I’ve replaced it with an introduction to the history of weak references in Java. Kragen Javier Sitaker (talk) 21:26, 17 February 2015 (UTC)
replies: text: Wain is user:Davew123, who has spent years inserting himself into various articles. 80.189.137.19 (talk) 13:56, 19 April 2015 (UTC)
thread_title:  removing weird Java text 

message: A description of how weak references are implemented would be useful.  — Preceding unsigned comment added by 81.191.74.4 (talk) 01:41, 24 February 2015 (UTC)
thread_title:  Implementation 

message: JavaScript supports associative arrays with weak references as keys, although enumerating the keys is not possible in this case. --Zzo38 (talk) 19:42, 31 August 2016 (UTC)
thread_title:  JavaScript WeakMap