Preventing Memory Leaks in an MQL4 MySQL Library
Summary
This document describes changes to an MQL4 library for reading data from MySQL, focusing on memory handling in its data-fetching function. The author reports that correcting allocation and release problems helped keep memory use stable during a test that ran for several hours and involved thousands of database connections and reads. The test used an expert advisor that requested data on every tick; the author notes that the small increase in memory could have come from MetaTrader 4 or other indicators.
The practical guidance is to keep the connection identifier local to the function, open connections for specific tasks, close them promptly, and call the library’s cleanup routine to release connections. The document also recommends transaction management when multiple connections may overlap. These are operational lessons for trading software that depends on external data, not evidence about a trading signal. The reported results are from one setup and are not a general benchmark; the author also advises consulting the original library’s usage description.
Key ideas
- The author traces memory growth to data handling in the library’s fetch function.
- The revised library reportedly kept memory use stable during a prolonged test with repeated reads.
- The connection identifier should be local to the operation that uses it.
- Connections should be opened for specific tasks and closed promptly after reading.
- Transaction management can help prevent concurrent database requests from interfering.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.