I have been using 'MemoryInUse()' to try to track down a memory leak that is crashing my Maple-based simulation. The problematic proc seems to be ProbDStarLNu which calculates the probablity of decay as a function of the angles of the decay product. It gets called a lot in acceptance rejection decay generation.
'MemoryInUse()' slows it down a lot. It also seemed to give weird results to me. I calculate the mem used on entry and then after the 4 trig functions have been called. The amount of mem 'in use' goes down after the trig functions are called. I was suspecting they were the source of the leak, but they seem almost an anti-leak.
This weird behavior caused me to write my own mem counting proc ('memUsed') based on summing over the results of 'mem:= kernelopts(memusage)'.
It is much faster. It gives nearly but not quite the same numbers. It still goes "backward" when the trig functions are called. Most of the mem growth comes from the algebra that follows the trig.
Why would that be?
I have included code for 'ProbDStarLNu'. It's pretty simple.