singleton question

From: tarmat (tarmat_at_btopenworld.com)
Date: 10/31/03


Date: Fri, 31 Oct 2003 15:30:47 +0530

I have a singleton class that looks a little like this:

class MyClass
{
private:

        //data

        MyClass()
        {
                Create();
        }

        void Create(); //initialization stuff

public:

        static MyClass* Instance()
        {
                static MyClass instance;

                return &instance;
        }

        //interface
};

This singleton class is used within multiple cpp files within my
project. It works fine in debug build but when I compile a release
build the MyClass ctor is called multiple times, one time for each
different cpp file it is called from.

Do you know why this is happening? I don't understand what's going on
at all. Surely it is only possible for the ctor to be called once
given this code.

Thanks for any enlightenment.