Entities are a known memory leak, IN CERTAIN CONDITIONS.
I have spent MUCH time discussing it with JCL, for years now...
BTW, 'memory leak' is not the correct term to use.
In normal usage the term 'memory leak' means memory that has 'escaped' the applications control.
In THIS case, acknex still has control over the memory, just your script no longer has...
But for the sake of simplicity, we will keep calling it a 'leak' for now...
Your leak may be coming from several sources. If you test with the example code
that Stromausfall posted above, it will take a LONG time to get any noticable memory loss.
Explaination of the 'certain conditions' can be found in point #1 and #3 below.
So read on...
1> You really should be using ENT_REMOVE to remove entities, not ptr_remove.
I've found ptr_remove can be a bit sloppy on memory cleanups with entities.
2> Any memory that gets 'lost' in this process is 'hiding' in the nexus area.
This can be retrieved/recycled by using level_load or level_mark/level_free.
READ THE MANUAL CAREFULLY ON THESE COMMANDS! They can be deadly... but often necessary.
3> If you are using the commands ENT_CLONE or ENT_CLONESKIN, then there is no way
to prevent memore loss EXCEPT by using something from point#2.
BTW the way you are testing memory consumption is the best way IMHO...
I hope this helps somewhat...