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 621245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:51:12+00:00 2026-05-13T18:51:12+00:00

This is a duplicate of: What is a singleton in C#? I don’t think

  • 0

This is a duplicate of: What is a singleton in C#?

I don’t think it is duplicate, as here what I am looking for is best strategy for releasing/disposing the Singleto object when not in use.

How to implement a Singleton so that object instance can be released/disposed when all it’s references are not in use? And when ever any body wants a Singleton instance it is lazy loaded on demand.

  • 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-05-13T18:51:12+00:00Added an answer on May 13, 2026 at 6:51 pm

    As some other answers say, Implementing the Singleton Pattern in C# is one of the best resources for Singletons in general.

    If you want your singleton to be released when it’s not referenced anywhere else, you might take your favorite pattern off the aforementioned site and wrap the instance into a WeakReference, for example something like:

    public sealed class Singleton
    {
        static private readonly WeakReference _instanceReference =
            new WeakReference(Singleton.LoadInstance());
        static public Singleton Instance
        {
            get { return Singleton.GetInstance(); }
        }
    
        static private Singleton() { }
    
        static private Singleton LoadInstance()
        {
            // load from expensive resource;
            return new Singleton();
        }
    
        static private Singleton GetInstance()
        {
            Singleton result = _instanceReference.Target as Singleton;
            if (result == null)
            {
                // TODO: consider thread safety
                result = LoadInstance();
                _instanceReference.Target = result;
            }
    
            return result;
        }
    
        private Singleton()
        {
            //
        }
    
    }
    

    Be aware that consumers most likely would merely call your Singleton.Instance and won’t create a reference by themselves, which means your resource would get reloaded quite often. I guess this pattern works best if the Singleton Instance would sometimes be a member of certain classes you pass around.

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

Sidebar

Related Questions

Closed as exact duplicate of this question . But reopened, as the other Singleton
Sorry if this is duplicate,I would think it would be but couldn't find anything.
Duplicate of this question . update - This is not an exact duplicate. See
I am sorry if this is a duplicate but I was not able to
Duplicate - this exact question was asked here - the only solution seems to
Possible Duplicate: Efficient way to implement singleton pattern in Java I was reading this
Apologize if this is duplicate - not sure how to word what Im trying
Possible Duplicate: A Singleton that is not globally accessible Do you know a good
Possible Duplicate: How to clone js object? This is another way to create a
Possible Duplicate: Null object in javascript Hi, I've read this thread about null in

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.