delete invalid pointer message when debugging

 

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.

 
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;
 
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 :)

Reason: