Proposition for reporting MEMORY LEAKS in strategy tester - page 3

 
Dominik Egert #:
You should post it as library. Aside of that, looks good.

Edit:
What about author and license, don't you want to add that as header to the file?

Ok - done. I'm a little bit awkward about license policy. Correct or not?

 
Dr Matthias Hammelsbeck #:

Ok - done. I'm a little bit awkward about license policy. Correct or not?

It is fine with me. Public Domain, as you have declared it.


 
Dominik Egert #:

Ill share my code for a heap memory tracer.

@Alain Verleyen , actually, it can be done more seemles integrated. Dont know if this can be accounted for "better".


The code is as is, and needs to be understood, its not recommended to use it in production, because it has a very slow search "algorithm", but it does work reliable.

It will brint out a list of object-ids, which can be used to find the objects in a second run, so that you can insert a "DebugBreak()" when this particulat object will be created. - Of course this only works, if the creation of the objects is deterministic. - Meaning, the sequence of ooperations may not change, as the IDs are createn on the go, and therefore, the code must produce the same "results" on the second run.


It is provided as is.

This content would go into an include .mqh file and you would simply include it into your projects. - No changes to your code are required.

To remove the code, simply remove the include file from your project. - Should work seemles, and could be extended with multiple types of queries and other stuff for more user-convenience.

Is it possible to detect the memory usage of each object?

 
hini #:

Is it possible to detect the memory usage of each object?

It depends on what kind of object you are talking about.

https://www.mql5.com/en/docs/basis/operations/other#sizeof

 
Vladislav Boyko #:

It depends on what kind of object you are talking about.

https://www.mql5.com/en/docs/basis/operations/other#sizeof

GUI class objects, which have pointers to other GUI class objects among themselves, cannot be measured accurately using sizeof .
 
hini #:
GUI class objects, which have pointers to other GUI class objects among themselves, cannot be measured accurately using sizeof .

The memory occupied by object A has no relation to the memory occupied by object B, which stores a pointer to object A. A pointer to the same object can be stored in several other objects.

I'm not clear on your wording "the memory usage of each object".

  • Using MQL_MEMORY_USED you can find out memory used by MQL5 program in MB (heap memory, stack is not taken into account)
  • If you want to calculate the memory occupied by a specific instance of a specific object, you can do that too. But you must correctly take dynamic arrays and strings into account if the object contains them.
 
Vladislav Boyko #:

The memory occupied by object A has no relation to the memory occupied by object B, which stores a pointer to object A. A pointer to the same object can be stored in several other objects.

I'm not clear on your wording "the memory usage of each object".

  • Using MQL_MEMORY_USED you can find out memory used by MQL5 program in MB (heap memory, stack is not taken into account)
  • If you want to calculate the memory occupied by a specific instance of a specific object, you can do that too. But you must correctly take dynamic arrays and strings into account if the object contains them.
Okay, thank you for your reply. I'll study it carefully.