G
Guest
Hi,
i created a singleton. This singleton read a config file in the constructor
and write it in the finalize. I got a big problèm, the finalize it's not
always call!! I don't know what do that it is call or not.. it's seem
random ! It's supose to call it when the application terminate.
I use the 4th pattern from this page :
http://www.yoda.arachsys.com/csharp/singleton.html
My singleton is in a dll.. It have only 1 other class (in another dll) who
use my singleton... And this class assign 0 to pointer when it not more need
the singleton.
I tried to add a "GC::Collect()" just before my app terminate.. no changes..
They are some problem with the singleton / garbage collector / finalize ?!
Here is my code (simplified):
public __sealed __gc class Singleton
{
public:
static Singleton* GetSingleton(){return m_Singleton;}
ObjectItem GetItem(String* _Module, String* _Name, Object*
_defaultValue);
Void SetItem(String* _Module, String* _Name, Object * _value);
//A try...
~Singleton();
private:
static Singleton(){};
//I tried with only the static constructor.. no changes..
Singleton();
//File management
Void WriteFile();
Void ReadFile();
///<summary>
/// The singleton
///</summary>
static Singleton* m_Singleton = new Singleton();
};
i created a singleton. This singleton read a config file in the constructor
and write it in the finalize. I got a big problèm, the finalize it's not
always call!! I don't know what do that it is call or not.. it's seem
random ! It's supose to call it when the application terminate.
I use the 4th pattern from this page :
http://www.yoda.arachsys.com/csharp/singleton.html
My singleton is in a dll.. It have only 1 other class (in another dll) who
use my singleton... And this class assign 0 to pointer when it not more need
the singleton.
I tried to add a "GC::Collect()" just before my app terminate.. no changes..
They are some problem with the singleton / garbage collector / finalize ?!
Here is my code (simplified):
public __sealed __gc class Singleton
{
public:
static Singleton* GetSingleton(){return m_Singleton;}
ObjectItem GetItem(String* _Module, String* _Name, Object*
_defaultValue);
Void SetItem(String* _Module, String* _Name, Object * _value);
//A try...
~Singleton();
private:
static Singleton(){};
//I tried with only the static constructor.. no changes..
Singleton();
//File management
Void WriteFile();
Void ReadFile();
///<summary>
/// The singleton
///</summary>
static Singleton* m_Singleton = new Singleton();
};