delete invalid pointer message when debugging

To add comments, please log in or register
Geester
280
Geester  

Hi,

I've noticed that when debugging an indicator in MT4, I'm seeing a series of "delete invalid pointer" messages in the terminal's expert tab.

In the indicator, every new object that I create is specifically deleted using "delete objName", prior to testing the object variable like so:-

   if(!CUtils::IsNull(TestConf))
     {
      delete TestConf;
     }

where the code for IsNull is as follows:-

bool CUtils::IsNull(CObject *object)
  {
   return (object==NULL || CheckPointer(object)==POINTER_INVALID);
  }

When I run the same indicator in the terminal, there are no such errors reported in the terminal's expert tab and the indicator runs as expected.

Any ideas why there might be this inconsistency between running in the debugger, and directly using the indicator in the terminal?

Many thanks.

nicholi shen
2392
nicholi shen  
Geester:

Hi,

I've noticed that when debugging an indicator in MT4, I'm seeing a series of "delete invalid pointer" messages in the terminal's expert tab.

In the indicator, every new object that I create is specifically deleted using "delete objName", prior to testing the object variable like so:-

where the code for IsNull is as follows:-

When I run the same indicator in the terminal, there are no such errors reported in the terminal's expert tab and the indicator runs as expected.

Any ideas why there might be this inconsistency between running in the debugger, and directly using the indicator in the terminal?

Many thanks.

The problem is you can have pointers to static objects, and if you try to delete a static object then you will obviously get errors. The correct way to delete an object is as follows. 

if (CheckPointer(obj) == POINTER_DYNAMIC)
   delete obj;
Geester
280
Geester  
nicholi shen:

The problem is you can have pointers to static objects, and if you try to delete a static object then you will obviously get errors. The correct way to delete an object is as follows. 

Awsome! Thanks for the heads-up with this Nicholi :)

To add comments, please log in or register