Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8701293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:21:46+00:00 2026-06-13T02:21:46+00:00

Possible Duplicate: Weak references What is this thing for? It seems to be a

  • 0

Possible Duplicate:
Weak references

What is this thing for?

It seems to be a way to create an object that the GC can collect early and if it gets collected early, I am supposed to just re-create it. That sounds to me like caching, but other StackOverflow questions say that this is a lousy cache strategy because the GC in practice will GC your object very eager and fast, (another Q that says weakreference make poor caches) sort of like using ASP.NET’s Cache and setting it to a very low cache eviction time limit.

Background: I was recently reading CLR code for TraceSource. In the constructor, the 1st thing that happens is that a WeakReference(this) is added to a static dictionary. Oddly it is only ever used in the Refresh method when TraceSource re-reads the config file for each TraceSource in the dictionary of weak references, but only if it hasn’t already been GC’d. And another StackOverflow question indicates this causes memory leaks.

So I’ve been reading about WeakReferences ever since and getting more and more confused.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:21:47+00:00Added an answer on June 13, 2026 at 2:21 am

    WeakReference is often used for implementing Weak Events. Event handlers are a frequent cause of memory leaks, particularly when you have a long-lived service with events that multiple instances subscribe to. If those instances fail to unregister their event handlers (either because the developer didn’t realize it was important or often due to exception cases not triggering the normal cleanup) then the lingering references keep the instances from being collected.

    Another good case is if you you want to associate additional data with an existing instance. For instance, you might have an ExtraWidgetInfo that you want to associate with a 3rd-party Widget. One way to create the association is to use a Dictionary. The problem is that now all of the Widgets are kept alive by the Dictionary itself, even if they are no longer used anywhere else. Using a WeakReference for the Widget references keeps the associated data from keeping Widgets alive past their intended expiration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Simple way to repeat a String in java How can I convert
Possible Duplicate: What is the most efficient way to clone a JavaScript object? (Most
Possible Duplicate: What are the reasons why Map.get(Object key) is not (fully) generic This
Possible Duplicate: Create an empty object in JavaScript with {} or new Object()? When
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: Why can templates only be implemented in the header file? I just
Possible Duplicate: How to wrap a Struct into NSObject Can the new Clang Objective-C

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.