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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:02:10+00:00 2026-05-12T06:02:10+00:00

I had encountered a problem while using Loki::Singleton , Loki::SmartPtr , and std::vector under

  • 0

I had encountered a problem while using Loki::Singleton, Loki::SmartPtr, and std::vector under VC express 2008. Following is my source.

#include <iostream>
#include <vector>
#include <loki/Singleton.h>
#include <loki/SmartPtr.h>

class Foo {
  public:
    std::vector<Loki::SmartPtr<Foo>> children ;
    void add() {
        Loki::SmartPtr<Foo> f = new Foo ;
        children.push_back(f) ;
    }
    Foo () {
    }
    ~Foo () {
    }
} ;

typedef Loki::SingletonHolder<Foo> SingletonFoo ;

int main ()
{
    std::cout << "Start" << std::endl ;
    SingletonFoo::Instance().add() ;
    std::cout << "End" << std::endl ;
}

Compiling and linking has no problem, but after the program finished, an error pops:

Windows has triggered a breakpoint in test.exe.
This may be due to a corruption of the heap, which indicates a bug in test.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while test.exe has focus.
The output window may have more diagnostic information.

It seems some memory are deleted twice, I am quite not sure. Is that a bug of VC or I miss used Loki?

Thanks in advance.

  • 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-12T06:02:10+00:00Added an answer on May 12, 2026 at 6:02 am

    As you’re using VC, you should be able to run your code in debug mode, step by stp (F10,F11) to see where it breaks.

    Anyway, looking at the Loki singleton code, it seems that the error comes from the assert in SingletonHolder::DestroySingleton() :

     SingletonHolder<T, CreationPolicy, L, M, X>::DestroySingleton()
    00837     {
    00838         assert(!destroyed_); // there, but it's a wild guess
    00839         CreationPolicy<T>::Destroy(pInstance_);
    00840         pInstance_ = 0;
    00841         destroyed_ = true;
    00842     }
    

    That function seems to be called by the LifetimePolicy (here DefaultLifetime) as this code suggests :

    00800     template
    00801     <
    00802         class T,
    00803         template <class> class CreationPolicy,
    00804         template <class> class LifetimePolicy,
    00805         template <class, class> class ThreadingModel,
    00806         class MutexPolicy
    00807     >
    00808     void SingletonHolder<T, CreationPolicy, 
    00809         LifetimePolicy, ThreadingModel, MutexPolicy>::MakeInstance()
    00810     {
    00811         typename ThreadingModel<SingletonHolder,MutexPolicy>::Lock guard;
    00812         (void)guard;
    00813         
    00814         if (!pInstance_)
    00815         {
    00816             if (destroyed_)
    00817             {
    00818                 destroyed_ = false;
    00819                 LifetimePolicy<T>::OnDeadReference();
    00820             }
    00821             pInstance_ = CreationPolicy<T>::Create();
    00822             LifetimePolicy<T>::ScheduleDestruction(pInstance_, // here
    00823                 &DestroySingleton);
    00824         }
    00825     }
    

    I’m not sure why it is called twice, but I guess the pointer to the singleton is first destroyed (the pointer, not the instance) on the SingletonHolder instance destruction and then the LifetimePolicy try to call it’s DestroySingleton() function…

    But I might be wrong, you’ll have to check that.

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

Sidebar

Ask A Question

Stats

  • Questions 204k
  • Answers 204k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try using undname.exe in your vc\bin dir. It didn't work… May 12, 2026 at 8:47 pm
  • Editorial Team
    Editorial Team added an answer Look at this documentation on using cursors in your stored… May 12, 2026 at 8:47 pm
  • Editorial Team
    Editorial Team added an answer SAPI can certainly do what you want. Start with an… May 12, 2026 at 8:47 pm

Related Questions

I had encountered strange problem while construct a unordeed_set<tuple<int,int>> . I had tried VC++8,
In one of my builds for an iPhone app, I had inadvertently created a
I've had a serious issue with my Visual Studio 2008 setup. I receive the
Some time ago I had to address a certain C# design problem when I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.