memory in multivariate polynomial ring over

59 views
Skip to first unread message

Martin R

unread,
Apr 9, 2026, 3:34:36 PM (2 days ago) Apr 9
to sage-devel
I was notified of a potential memory leak.  Am I doing something wrong below?  Why does memory usage go up?

Martin

    k = Integers(9)
    R.<x, y> = k[]
    base = ps.memory_info().rss
    cnt = 0
    while True:
        if cnt % 1000 == 0:
            mem = ps.memory_info().rss - base
            print(f"{mem/1e6 :.2f} MB, count {cnt}")
        u = k(cnt) * y
        cnt += 1

Vincent Macri

unread,
Apr 9, 2026, 6:46:40 PM (2 days ago) Apr 9
to sage-...@googlegroups.com
This seems like a bug (I have no idea what the cause might be).

Here is a simpler example that also shows a memory leak (although memory
increases slower than in your example).


    k = Integers(9)
    R.<x, y> = k[]
    u = k(1)
    base = ps.memory_info().rss
    cnt = 0
    while True:
        if cnt % 1000 == 0:
            mem = ps.memory_info().rss - base
            print(f"{mem/1e6 :.2f} MB, count {cnt}")
        u = -u
        cnt += 1


Dima Pasechnik

unread,
Apr 9, 2026, 8:29:04 PM (2 days ago) Apr 9
to sage-...@googlegroups.com
libsingular is leaky, unfortunately.

see e.g. <https://github.com/sagemath/sage/issues/27261> and links there

Martin R

unread,
Apr 10, 2026, 3:38:44 AM (21 hours ago) Apr 10
to sage-devel
Are you sure that this is a bug in singular?

Two things: 1) I could not reproduce (on current develop, singular 4.4.1, ubuntu 24.04.4) a memory leak using Vincent's example above.  Replacing `u = -u` with `u = 2 * y`, however, does leak.

2) I tried to reproduce the leak in singular, but couldn't.  I did singular.console() and ran

option(mem);
ring R = (integer, 3, 2),(x,y), dp;
bigint cnt = 0;
bigint mem_start = memory(0);
bigint mem_used;
poly u;
while(1) {
    u = 2 * y;
    cnt++;

    if (cnt % 1000 == 0) {
        mem_used = memory(0) - mem_start;
        print(cnt);
        print(mem_used);
    }
}

Note that I have no clue about how to use singular properly, and of course there might be a difference between singular and libsingular.

But I think it would be great to have something which is better to report to singular.

Martin

Martin R

unread,
Apr 10, 2026, 3:45:30 AM (21 hours ago) Apr 10
to sage-devel
sorry, that should be cnt = cnt + 1, if cnt is a bigint.

Nils Bruin

unread,
Apr 10, 2026, 11:58:34 AM (13 hours ago) Apr 10
to sage-devel
On Friday, 10 April 2026 at 00:38:44 UTC-7 axio...@yahoo.de wrote:
Are you sure that this is a bug in singular?
At least some leaking behaviours we have encountered in the past have been traced back to how our cython shim connects to libsingular. It was written with only partial knowledge about the undocumented way that singular tracks things like reference counting. This has led to some structural leaks where "singular rings" are basically immortal, because no-one could figure out when it's safe to delete them. That was definitely a leak. I don't know if that was ever fixed; I would assume not.

I thought that at least for individual elements (as in the example here) the situation was not as bad. However, it's not impossible that the leaking here happens in the form of polynomial rings over Z/9 that get recreated rather than reused.

One would not expect that the leaks we're experiencing would be reproducible in singular proper.

In the mean time, "oscar" has also developed, which has more official ties with singular development. It may be that the memory model of singular is now better documented through that project (possibly in the form of the interfacing julia code).
 

Vincent Macri

unread,
Apr 10, 2026, 2:32:10 PM (10 hours ago) Apr 10
to sage-...@googlegroups.com
On 2026-04-10 1:38 a.m., 'Martin R' via sage-devel wrote:
> Two things: 1) I could not reproduce (on current develop, singular
> 4.4.1, ubuntu 24.04.4) a memory leak using Vincent's example above. 
> Replacing `u = -u` with `u = 2 * y`, however, does leak.

The memory leak I posted was in Sage 10.7. I tested it again and found
something strange. The memory leak I posted happens when I run it in
Jupyter QtConsole, but not when I run it in a Sage command line terminal.

Reply all
Reply to author
Forward
0 new messages