A quick valgrind run for from sage.all import sqrt T2 = sqrt(2) for b in range(num := 100_000): C = sqrt(T2)
confirms that it is in pynac: ==3947957== 799,912 bytes in 99,989 blocks are definitely lost in loss record 1,299 of 1,300 ==3947957== at 0x484182F: malloc (vg_replace_malloc.c:431) ==3947957== by 0x1A6D3B07: sig_malloc (memory.c:1898) ==3947957== by 0x1A6D3B07: __pyx_f_4sage_3ext_6memory_sage_sig_malloc (memory.c:1517) ==3947957== by 0x13D0EC2B: ??? ==3947957== by 0x13D0FEFD: ??? ==3947957== by 0x1FBA2393: GiNaC::numeric::integer_rational_power(GiNaC::numeric&, GiNaC::numeric const&, GiNaC::numeric const&) (numeric.cpp:1621) ==3947957== by 0x1FBA266D: GiNaC::numeric::integer_rational_power(GiNaC::numeric&, GiNaC::numeric const&, GiNaC::numeric const&) (numeric.cpp:1614) ==3947957== by 0x1FBA94DC: GiNaC::rational_power_parts(GiNaC::numeric const&, GiNaC::numeric const&, GiNaC::numeric&, GiNaC::numeric&, bool&) (numeric.cpp:1692) ==3947957== by 0x1FBAA2AF: GiNaC::numeric::power(GiNaC::numeric const&) const (numeric.cpp:1916) ==3947957== by 0x1FBBA918: GiNaC::power::eval(int) const (power.cpp:536) ==3947957== by 0x1FB09107: GiNaC::ex::construct_from_basic(GiNaC::basic const&) (ex.cpp:923) ==3947957== by 0x1FBB9D89: ex (ex.h:314) ==3947957== by 0x1FBB9D89: GiNaC::power::eval(int) const (power.cpp:507) ==3947957== by 0x1FB09107: GiNaC::ex::construct_from_basic(GiNaC::basic const&) (ex.cpp:923) ==3947957== On Wednesday, July 5, 2023 at 5:24:27 PM UTC+2 Gonzalo Tornaria wrote: > This slowly and inexorably goes on. Computing `sqrt(T2)` leaks 32 bytes > each and every time (asymptotically). > > Found by a student who, through no fault of himself, brought down our > server (unable to ssh in until the OOM triggered -- but since the leak is > slow it takes a while to trash 16G of swap). > > === > $ cat memleak.py > from sage.all import sqrt > T2 = sqrt(2) > import psutil > ps = psutil.Process() > base = ps.memory_info().rss > for a in range(1, 10): > for b in range(num := 100_000): > C = sqrt(T2) > mem = ps.memory_info().rss - base > print(f"{mem/1e6 :.2f} MB ({mem/a/num :.2f} bytes/iter)") > $ sage memleak.py > 2.70 MB (27.03 bytes/iter) > 5.95 MB (29.74 bytes/iter) > 9.19 MB (30.64 bytes/iter) > 12.44 MB (31.09 bytes/iter) > 15.41 MB (30.82 bytes/iter) > 18.65 MB (31.09 bytes/iter) > 21.90 MB (31.28 bytes/iter) > 25.14 MB (31.43 bytes/iter) > 28.39 MB (31.54 bytes/iter) > === > > Replace the 10 in the outer loop by something larger at your own peril > (each outer iteration will take 3.2M so 10_000 should kill a laptop in an > hour or two). > > This is with system sagemath 10.0 but it also happens with 9.6, 9.7, 9.8 > and 10.0 in cocalc.com. > > Best, > Gonzalo > > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/eb17a08e-1576-4ab6-b09a-8333e3d55caan%40googlegroups.com.