Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Tracing garbage collection
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Strong and weak references == The garbage collector can reclaim only objects that have no references pointing to them either directly or indirectly from the root set. However, some programs require [[weak reference]]s, which should be usable for as long as the object exists but should not prolong its lifetime. In discussions about weak references, ordinary references are sometimes called [[strong reference]]s. An object is eligible for garbage collection if there are no strong (i.e. ordinary) references to it, even though there still might be some weak references to it. A weak reference is not merely just any pointer to the object that a garbage collector does not care about. The term is usually reserved for a properly managed category of special reference objects which are safe to use even after the object disappears because they ''lapse'' to a safe value (usually <code>null</code>). An unsafe reference that is not known to the garbage collector will simply remain dangling by continuing to refer to the address where the object previously resided. This is not a weak reference. In some implementations, weak references are divided into subcategories. For example, the [[Java virtual machine|Java Virtual Machine]] provides three forms of weak references, namely [[soft reference]]s,<ref name=":0">{{cite web |url=http://docs.oracle.com/javase/7/docs/api/java/lang/ref/SoftReference.html |title=Class SoftReference<T> |publisher=Oracle |website=Java™ Platform Standard Ed. 7 |access-date=25 May 2013}}</ref> [[phantom reference]]s,<ref>{{cite web |url=http://docs.oracle.com/javase/7/docs/api/java/lang/ref/PhantomReference.html |title=Class PhantomReference<T> |publisher=Oracle |website=Java™ Platform Standard Ed. 7 |access-date=25 May 2013}}</ref> and regular weak references.<ref>{{cite web |url=http://docs.oracle.com/javase/7/docs/api/java/lang/ref/WeakReference.html |title=Class WeakReference<T> |publisher=Oracle |website=Java™ Platform Standard Ed. 7 |access-date=25 May 2013}}</ref> A softly referenced object is only eligible for reclamation if the garbage collector decides that the program is low on memory. Unlike a soft reference or a regular weak reference, a phantom reference does not provide access to the object that it references. Instead, a phantom reference is a mechanism that allows the garbage collector to notify the program when the referenced object has become ''phantom reachable''. An object is phantom reachable, if it still resides in memory and it is referenced by a phantom reference, but its [[finalizer]] has already executed. Similarly, [[.NET Framework|Microsoft.NET]] provides two subcategories of weak references,<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/ms404247.aspx |title=Weak References |publisher=Microsoft |website=.NET Framework 4.5 |access-date=25 May 2013}}</ref> namely long weak references (tracks resurrection) and short weak references.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)