BugRequest: "Access violation" while accessing static function - page 2

 
Carl Schreiber:
Can it be that EAs and indicators compiled before Beta build 1930 will occasionally crash on terminals build 1930+?

I happens with some build, not sure it's fixed.

Anyway here it is an other problem as the code is compiled with the last build.

 
Christian Stern:

Some how it is gone again. Maybe it has something to do while i've reduced the number of entires in this array. I've also removed all the GetPointer() at destruct level. I'am not sure if i should use CheckPointer(). The objects will be always initiated.

Until one is not for some reason. I recommend you to always use CheckPointer() before delete.
 
Alain Verleyen:
Until one is not for some reason. I recommend you to always use CheckPointer() before delete.

bad idead ... i've updated my code and since i get after 5min uptime access violation. Lots's of compiling and application restarts later i roll back my code and it's back working.

In my opinien there should be no need to do the check. You have called "new object()" and the delete function should do the check.


I am getting a bit scared because i plan to play with some real money and this memory errors does not make me feel good. I try to code cleanly and not doing crazy stuff. I like the language and the all around but this memory things ....mmmh

 
Alain Verleyen:
Until one is not for some reason. I recommend you to always use CheckPointer() before delete.

Exactly, this. 


#include <object.mqh>

void OnStart() 
{
   CObject *foo = new CObject;
   if(safe_delete(foo)) 
      Print("deleted foo");
      
   CObject bar;
   if(!safe_delete(&bar))
      Print("did not delete bar");
}

bool safe_delete(void *ptr)
{
   if(CheckPointer(ptr) == POINTER_DYNAMIC) {
      delete ptr;
      return true;
   }
   return false;
}
 
Christian Stern:

bad idead ... i've updated my code and since i get after 5min uptime access violation. Lots's of compiling and application restarts later i roll back my code and it's back working.

In my opinien there should be no need to do the check. You have called "new object()" and the delete function should do the check.


I am getting a bit scared because i plan to play with some real money and this memory errors does not make me feel good. I try to code cleanly and not doing crazy stuff. I like the language and the all around but this memory things ....mmmh

It's actually a good idea. I am working with complex code and I don't have "access violation". Only one I had, was in a place there was no checking.

Now if you don't want good advice, up to you.

 
Alain Verleyen:

It's actually a good idea. I am working with complex code and I don't have "access violation". Only one I had, was in a place there was no checking.

Now if you don't want good advice, up to you.

thank you for your advice, i am always know to honor them. I just would say with this, that simply the delete() handle should try to delete this. And all necassary code should be implemented there.

Better would be, checking the return of delete to make sure it has been deleted successful.

 
Christian Stern:

thank you for your advice, i am always know to honor them. I just would say with this, that simply the delete() handle should try to delete this. And all necassary code should be implemented there.

Better would be, checking the return of delete to make sure it has been deleted successful.

I didn't see any code from you about "delete() handle" so I can only guess what you are doing.

nicholishen's code shows exactly what I am talking about. Is it what you also mean ?

Reason: