Content deleted Content added
m Change "Boost framework" to "Boost library" |
Citation bot (talk | contribs) Alter: url. URLs might have been anonymized. Add: archive-date, archive-url, title. Changed bare reference to CS1/2. | Use this bot. Report bugs. | Suggested by Josve05a | Linked from User:Josve05a/cite/wayback | #UCB_webform_linked 959/1938 |
||
Line 1:
In [[computer programming]], a '''weak reference''' is a [[reference (computer science)|reference]] that does not protect the referenced [[object (computer science)|object]] from collection by a [[garbage collection (computer science)|garbage collector]], unlike a strong reference. An object referenced ''only'' by weak references – meaning "every chain of references that reaches the object includes at least one weak reference as a link" – is considered ''[[weakly reachable]],'' and can be treated as [[unreachable memory|unreachable]] and so may be collected at any time. Some garbage-collected languages feature or support various levels of weak references, such as [[C Sharp (programming language)|C#]], [[Java (programming language)|Java]], [[Lisp (programming language)|Lisp]], [[OCaml]], [[Perl]], [[Python (programming language)|Python]]<ref>[https://docs.python.org/3/library/weakref.html 8.8. weakref — Weak references], The Python Standard Library</ref> and [[PHP]] since the version 7.4.<ref>{{Cite web|url=https://www.php.net/manual/en/class.weakreference.php|title = PHP: WeakReference - Manual}}</ref>
==Uses==
Line 14:
== Variations ==
Some languages have multiple levels of weak reference strength. For example, [[Java (programming language)|Java]] has, in order of decreasing strength, [[soft reference|soft]], weak, and [[phantom reference|phantom]] references, defined in the [[Java package|package]] [[Java Platform, Standard Edition#java.lang.ref|java.lang.ref]].<ref>{{cite web |last=Nicholas |first=Ethan |url=
In C#, weak references are distinguished by whether they track [[object resurrection]] or not. This distinction does not occur for strong references, as objects are not [[finalization|finalized]] if they have any strong references to them. By default, in C# weak reference do not track resurrection, meaning a weak reference is not updated if an object is resurrected; these are called '''short weak references''', and weak references that track resurrection are called '''long weak references'''.{{sfn|Goldshtein|Zurbalev|Flatow|2012|p=[https://books.google.com/books?id=D3J58cs-i44C&pg=PA131&q=resurrection#v=onepage&q=resurrection 131]}}
Line 143:
=== Java ===
* [http://www.pawlan.com/monica/articles/refobjs/ Java developer article: 'Reference Objects and Garbage Collection']
* {{cite web |last=Nicholas |first=Ethan |url=
* [http://rcache.sourceforge.net/ RCache - Java Library for weak/soft reference based cache]
* [http://www.ibm.com/developerworks/java/library/j-jtp11225/ Java theory and practice: Plugging memory leaks with weak references]
|