Memory leaks at mql4 when new object is created when initialising of class member at constructor time

To add comments, please log in or register
Alexander Nomad
20
Alexander Nomad  

I get memory leaks warnings at Mt4 "Experts" tab when I changed timeframe.

 

I'm using mql4.


To reproduce this issue just create simple indicator and paste this code.

class CObject

{
public:
   CObject() {}
   CObject(const CObject& obj) { }
};

CObject make_wrapper(const CObject& obj)
{
   CObject objtmp(obj);
   return objtmp;
}

class CTest
{
public:
   CTest(const CObject& obj) : _obj(make_wrapper(obj))
   {
   }
   
private:
   CObject _obj;
};



int init()

{

   CObject obj;

   CTest test(obj);

   return 0;

}



int deinit()

{

   return 0;

}



int start()

{

   return 0;

}


There is no any dynamic memory allocation. Why does this happen?

Alain Verleyen
38701
Alain Verleyen  

It is a compiler bug, resulting in the destructor not being call for temporary object. It has been fixed in recent ME build (around 2230) for mql5. Not sure if (and when) they will make it available for MT4.

A temporary object is created here :

   return objtmp;

So actually this bug occurs because you don't use pointers.

To add comments, please log in or register