In the code below VLD detects a memory leak if TestClass and getStaticObject are defined in a DLL. The DLL is built without VLD.
```
// some.dll
class TestClass
{
public:
TestClass()
{
buffer = new char[10];
}
~TestClass()
{
delete[] buffer;
}
private:
char* buffer;
};
TestClass& getStaticObject(void)
{
static TestClass object;
return object;
}
// ...
// end of some.dll
int main()
{
getStaticObject();
return 0;
}
```
Comments: VLD has no means of knowing that you were allocating a static object. You can either cause all your static objects to get initialized, then report all leaks as detected, then proceed with finding your leaks, or you can temporarily disable VLD by calling VLDDisable() when initializing your static objects. Beware of threading issues though if your application allocates memory from multiple threads.
```
// some.dll
class TestClass
{
public:
TestClass()
{
buffer = new char[10];
}
~TestClass()
{
delete[] buffer;
}
private:
char* buffer;
};
TestClass& getStaticObject(void)
{
static TestClass object;
return object;
}
// ...
// end of some.dll
int main()
{
getStaticObject();
return 0;
}
```
Comments: VLD has no means of knowing that you were allocating a static object. You can either cause all your static objects to get initialized, then report all leaks as detected, then proceed with finding your leaks, or you can temporarily disable VLD by calling VLDDisable() when initializing your static objects. Beware of threading issues though if your application allocates memory from multiple threads.