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

  • Home
  • SEARCH
  • 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 1010041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:01:14+00:00 2026-05-16T09:01:14+00:00

I was reading around a lot about singleton. I am thinking about the dead

  • 0

I was reading around a lot about singleton. I am thinking about the dead reference problem between singletons. In every primer on net , this problem is encountered when one singleton calls other singleton in its destructor, and that singleton is already destroyed, say Log singleton can be called from destructor of many other singletons.

I can’t imagine when in other case ( except referencing other singletons in dtr ), the dead reference would be a problem. Can you give me a real world example in which such a problem exists , and how can I solve it ?

The thing is that I need to implement a couple of singletons in our project, which all communicate with each other, and I am having real hard time to choose the right way. Please do not say not to use a singleton, because that’s not my decision.

  • 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-16T09:01:15+00:00Added an answer on May 16, 2026 at 9:01 am

    Copied from here: Finding C++ static initialization order problems (Nobody would have followed just a link sorry)

    Also see this article: C++ Singleton design pattern

    Destruction Problems:

    There is a potential problem of accessing the object after it has been destroyed. This only happens if you access the object from the destructor of another global variable (by global I am refering to any non local static variable).

    Solution you must make sure you force the order of destruction.
    Remember the order of destruction is the exact inverse of the order of construction. So if you access the object in your destructor you must gurantee that the object has not been destroyed. To do this you must just gurantee that the object is fully constructed before the calling object is constructed.

    class B
    {
        public:
            static B& getInstance_Bglob;
            {
                static B instance_Bglob;
                return instance_Bglob;;
            }
    
            ~B()
            {
                 A::getInstance_abc().doSomthing();
                 // The object abc is accessed from the destructor.
                 // Potential problem.
                 // You must guarantee that abc is destroyed after this object.
                 // To gurantee this you must make sure it is constructed first.
                 // To do this just access the object from the constructor.
            }
    
            B()
            {
                A::getInstance_abc();
                // abc is now fully constructed.
                // This means it was constructed before this object.
                // This means it will be destroyed after this object.
                // This means it is safe to use from the destructor.
            }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With all the hype around parallel computing lately, I've been thinking a lot about
Lately I've been thinking a lot about building a website/blog/community oriented site. However I
I am currently using Java, I've read a lot about Erlang on the net,
I've been reading up a lot about transactional memory lately. There is a bit
I've been reading a lot of stuff about functional programming lately, and I can
I've been reading a lot of articles that suggest putting a Memcached (or Velocity,
I'm building an asp.net MVC application where users can attach a picture to their
I am using the Zend Framework but my question is broadly about sessions /
I am VERY new to ASP.NET. I come from a VB6 / ASP (classic)
As of last night, I decided to start learning about WPF and have been

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.