Features of the mql5 language, subtleties and tricks - page 132

 
Igor Makanu:

wrap in class calculation of indicator - bind buffers to class fields

Alas...
It didn't work. Even if the buffer is inside the class and the handle, all the internal intermediate calculation buffers created remain in RAM even after the class instance is deleted.

The memory is cleared only by changing the TF.

The command of memory cleaning by handle is obviously missing. For example MemErase( int handle);

 
Nikolai Semko:

Alas...
It didn't work. Even if the buffer is inside the class and the handle, all the internal intermediate calculation buffers created remain in RAM even after the class instance is deleted.

The memory is cleared only by changing the TF.

What is obviously missing is a command intended to clear the memory by handle. For example MemErase( int handle);

1. did you check the combinations of an object pointer and an object instance (I mean *)?

2. did you write the destructor and delete the array size in it? (ArrayFree() and ArrayResize(arr,0,0) )

 
Nikolai Semko:

Alas...
It didn't work. Even if the buffer is inside the class and the handle, all the internal intermediate calculation buffers created remain in RAM even after the class instance is deleted.

The memory is cleared only by changing the TF.

What is obviously missing is a command intended to clear the memory by handle. For example MemErase( int handle);

And you didn't use IndicatorRelease?

But still I think it is an empty undertaking. What for do you need it? To draw animations? And for trading? To average the Moving Average until it reaches a straight line?

 
Nikolai Semko:

Alas...
It didn't work. Even if the buffer is inside the class and handle, all the intermediate buffers created internally still remain in RAM even after the class instance is deleted.

The memory is cleared only by changing the TF.

Clearly there is a missing command to clear memory by handle. For example MemErase( int handle);

The terminal stores caches for some time, even if the program doesn't use them.

You can catch how much time the memory is released.

 
Alexey Viktorov:

Have you used IndicatorRelease?

But still, I think it's a waste of time. Tell me, what do you need it for? To draw cartoons? And for trading? To average the Moving Average until it reaches a straight line?

Yes, thank you, Alexey. I had forgotten about this function. Seen it before, but never used it.

I tried it. Something goes wrong. It deletes it, but after deleting it, everything stops.

I simply added one line of code to the DrawSetup() function before calculation of the indicator with the following parameters.

IndicatorRelease(handle);
handle=iMA(_Symbol,_Period,per1,0,MaMethod,PriceBase);
for(int i=0;i<N;i++) handle=iMA(_Symbol,_Period,per2,0,MaMethod,handle);

The indicator simply stops working and I can't understand the reason yet.

Alexey Viktorov:

I think it is a futile idea. What for do I need it? To draw cartoons? And for trading? To average the Moving Average until it reaches a straight line?

I absolutely agree with you. It's just a useless toy.

 
Andrey Khatimlianskii:

The terminal keeps the caches for a while, even if the programme does not use them.

You can time how long it takes for the memory to free up.

I waited 6 minutes and still nothing was cleared.

 
Igor Makanu:

1. did you check the combinations of object pointer and object instance (I mean *)?

2. did you write the destructor and delete the array size in it? (ArrayFree() and ArrayResize(arr,0,0) )

1. Yes, I did it through a pointer, new and delete.

2. So there is no array. I.e. there are internal arrays but they don't have names. There is only the handle number.

And at each iteration of the for loop, the handle variable's value increases by one. That is, inner buffers are being multiplied and all the previous ones participate in calculation of the next one.

According to the logic, we should do IndicatorRelease(handle); before another completely new calculation of the indicator, but I already wrote above that it will kill the indicator. It is not clear why.

 
Nikolai Semko:

Yes, thank you, Alexey. I had forgotten about that function. Seen it before, but never used it.

Tried it. Something's going wrong. It deletes it, but after deleting it, everything stops.

I simply added one line of code to the DrawSetup() function before calculation of the indicator with the following parameters.

The indicator simply stops working and I am still unable to understand the reason.

I absolutely agree with you. It is just a useless toy.

That's not what I was thinking. I think we should make a couple of handlers, like a chart enumerator

currChart=ChartNext(prevChart); // на основании предыдущего получим новый график

And once you get a new Handle, the used Handle can be thrown away like the used ...

 
Alexey Viktorov:

That's not what I was thinking. I think you have to do a couple of handfuls, like a graph search

And once you get a new handle, the used one can be discarded like the used one ...

that won't work.

 
Nikolai Semko:

No way

Why not?
Reason: