{"id":3583,"date":"2013-08-07T07:00:00","date_gmt":"2013-08-07T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/08\/07\/weak-references-have-no-effect-on-object-lifetime\/"},"modified":"2013-08-07T07:00:00","modified_gmt":"2013-08-07T07:00:00","slug":"weak-references-have-no-effect-on-object-lifetime","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130807-00\/?p=3583","title":{"rendered":"Weak references have no effect on object lifetime"},"content":{"rendered":"<p>The <code>Weak&shy;Reference<\/code> class lets you retain a reference to an object while still permitting the object to be garbage collected. When that happens, then the <code>Is&shy;Alive<\/code> property is <code>false<\/code> and the <code>Target<\/code> property is <code>null<\/code>. (<a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/08\/11\/10048629.aspx\">Related discussion<\/a>.)\n Note, however, that weak references do not alter the decision of the garbage collector whether or not an object is garbage. It merely lets you observe the garbage collector&#8217;s decision.\n Some people think that <code>Weak&shy;Reference<\/code> means &#8220;Treat this as a regular (strong) reference most of the time, but if there is memory pressure, then you can reclaim the object.&#8221; This type of reference is called a <code>Soft&shy;Reference<\/code> in Java, but the CLR has no analogous concept as far as I&#8217;m aware. In the CLR, weak references do not extend the lifetime of an object.<\/p>\n<p> It&#8217;s sort of like the Prime Directive from Star Trek: Weak references follow a policy of non-interference with the natural course of the GC. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Weak&shy;Reference class lets you retain a reference to an object while still permitting the object to be garbage collected. When that happens, then the Is&shy;Alive property is false and the Target property is null. (Related discussion.) Note, however, that weak references do not alter the decision of the garbage collector whether or not an [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-3583","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The Weak&shy;Reference class lets you retain a reference to an object while still permitting the object to be garbage collected. When that happens, then the Is&shy;Alive property is false and the Target property is null. (Related discussion.) Note, however, that weak references do not alter the decision of the garbage collector whether or not an [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=3583"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3583\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=3583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=3583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=3583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}