I have been struggling with memory leaks for awhile, and finally tracked it down to the use of the built-in mathematical constants like pi, e, etc.
As a minimal example, running the code:
while pi<4:
x=0
will gradually exhaust all available memory. The same is true if pi is replaced by e, euler_gamma etc. (But not if pi is replaced with 3, for example.)
Stopping execution does not free the memory, nor does garbage collection. The only way to recover the memory seems to be to restart the sage process.
If I run print(get_memory_usage()) sage doesn't think any additional memory is being used, however the python process is rapidly consuming memory.
Memory is also leaked numerically approximating constants, so
while true:
x=N(pi)
similarly leaks memory, whereas replacing x=N(pi) by x=pi does not.
I have observed this behavior in versions 8.2, 8.6 and 9.2.