Significant memory leak using mathematical constants

94 views
Skip to first unread message

agrea...@gmail.com

unread,
Nov 7, 2020, 3:40:02 PM11/7/20
to sage-devel
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.

I found this old related bug report in the tracker: https://trac.sagemath.org/ticket/27536 and added a comment, however this issue seems to be broader than what is described there.



Dima Pasechnik

unread,
Nov 8, 2020, 10:55:12 AM11/8/20
to sage-devel
thanks for a short example, it is helpful.
now someone needs to dig into pynac code to understand where the memory leak is coming from.


--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/15fc0fd3-950e-449c-aeb0-0972c59ddfabn%40googlegroups.com.

Nils Bruin

unread,
Nov 10, 2020, 4:42:55 AM11/10/20
to sage-devel
On Sunday, November 8, 2020 at 7:55:12 AM UTC-8, Dima Pasechnik wrote:
thanks for a short example, it is helpful.
now someone needs to dig into pynac code to understand where the memory leak is coming from.

I've commented on the ticket -- I have a pretty good candidate for where the leak might be coming from (what seems to be an extra incref exactly in the "constant" codepath ...)

Dima Pasechnik

unread,
Nov 10, 2020, 7:13:07 AM11/10/20
to sage-devel
Upstream appears to be active, I've opened
https://github.com/pynac/pynac/issues/359

>
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/492d8893-670a-4d98-b04d-f074c18d3ccdo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages