Memory Leak Sentinel
MQL4 gives no heap introspection at all - there is no function that reports how many dynamic arrays or class instances are currently allocated. Chart objects are the one countable resource the platform exposes directly through ObjectsTotal(), which makes them the practical proxy for "is this program leaking" during development of any panel, dashboard or drawing tool that creates and deletes objects every tick. A naive check comparing ObjectsTotal() between two ticks is noisy on its own: a well-behaved panel that deletes and recreates N objects every OnTick legitimately shows the count swing by +N and -N within a single cycle if sampled mid-rebuild. This sentinel instead requires several consecutive growing cycles (configurable, three by default) before raising a GROWING verdict, absorbing that normal rebuild churn while still catching a genuine leak within a handful of cycles. For anything the sentinel cannot see directly - a dynamic array a caller tracks, a custom resource pool - CheckCycle() accepts an optional custom counter and applies the identical trend logic to it, so one sentinel instance can watch both chart objects and a caller's own count together. Notes and limitations - ObjectsTotal(0, -1, -1) counts every object on the chart, including ones created by other indicators/scripts/manual drawing - the sentinel cannot attribute growth to a specific source. Run it on a chart otherwise free of unrelated object churn during testing, or track only a prefixed subset via the custom-counter slot instead. - The sentinel has no memory of individual object names, only counts - it cannot tell you WHICH objects are leaking, only THAT the count is growing. Pair it with manual object-name auditing (or ObjectsTotal/ObjectName by prefix) once a leak is flagged. - State resets to LEAK_VERDICT_INSUFFICIENT_DATA whenever Init() is called again or a new instance is created - it is in-memory only and does not survive an EA restart.
Script · MT5 · v1.0 · Free
About Memory Leak Sentinel
Memory Leak Sentinel is a script for MetaTrader 5. It has 2 settings, such as Cycles per phase and Grow streak needed. MQL source code included.
Files in the download: MemoryLeakSentinel.mq5.mqh, MemoryLeakSentinel.txt, MemoryLeakSentinelDemo.ex5, MemoryLeakSentinelDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Cycles per phase | 6 | Simulated cycles to run in each phase |
| Grow streak needed | 3 | Consecutive growing cycles before GROWING is raised |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Dashboards & Scanners · Trend · MT5 Script · MQL5 Source Code