How to free up memory after the service finishes executing the task?

 

I created a service to run every 4 hours to analyze 35 currency pairs for all time frames from M30~ MN. After the analysis is complete, the service still takes up 9.5MB of RAM and slows down the computer. I had to Stop and then click Start again to free up the memory to 1.5MB as before running the service. I have researched and found out that the reason the service takes up so much memory is because the iCustom() function has loaded indicators so it takes up memory but does not free it after it has finished using it. I have used local variables in the functions so that when the execution is finished, those variables are freed but the memory is still at 9.5MB. Is there a way to free up all the memory after each execution?

 
Nguyen Van Luong:

I created a service to run every 4 hours to analyze 35 currency pairs for all time frames from M30~ MN. After the analysis is complete, the service still takes up 9.5MB of RAM and slows down the computer. I had to Stop and then click Start again to free up the memory to 1.5MB as before running the service. I have researched and found out that the reason the service takes up so much memory is because the iCustom() function has loaded indicators so it takes up memory but does not free it after it has finished using it. I have used local variables in the functions so that when the execution is finished, those variables are freed but the memory is still at 9.5MB. Is there a way to free up all the memory after each execution?

you can use IndicatorRelease function

https://www.mql5.com/en/docs/series/indicatorrelease

Documentation on MQL5: Timeseries and Indicators Access / IndicatorRelease
Documentation on MQL5: Timeseries and Indicators Access / IndicatorRelease
  • www.mql5.com
The function removes an indicator handle and releases the calculation block of the indicator, if it's not used by anyone else. Return Value Returns...
 
Paul Anscombe #:

you can use IndicatorRelease function

https://www.mql5.com/en/docs/series/indicatorrelease

Done! Thank you so much!