I think that here you are seeing caching taking place, rather than a memory leak. This is what I tried:
sage: import cypari2 sage: pari = cypari2.Pari() sage: def test(N): ....: for a in range(1, N): ....: K = NumberField(x^2+a, 'w') ....: m = K.class_group().order ....: print(pari.getheap()) ....: sage: %time test(10**3) [7950, 1451665] CPU times: user 2.86 s, sys: 45.5 ms, total: 2.91 s Wall time: 2.92 s sage: %time test(10**3) [7950, 1451665] CPU times: user 160 ms, sys: 2.65 ms, total: 163 ms Wall time: 163 ms sage: %time test(10**4) [83505, 19297360] CPU times: user 29.6 s, sys: 336 ms, total: 30 s Wall time: 30.1 s sage: %time test(10**4) [83505, 19297360] CPU times: user 1.33 s, sys: 4.32 ms, total: 1.33 s Wall time: 1.33 s I assume that the huge reduction in time for the second run of the test function is due to caching, and that the extra space on the heap is used by cached objects. - Marc On Wednesday, September 4, 2024 at 7:09:37 AM UTC-6 Georgi Guninski wrote: > Probably this shares the same bug as [1] > > Calling `NumberField().class_group().order()` in a loop of size N: > #10^3 leaks: 40.03 MB 40026112 pari= [7950, 1451665] > #10^4 leaks: 338.49 MB 338493440 pari= [83505, 19297360] > > The leak appears to be in the pari heap. > > Code .sage: > ==== > #Author Georgi Guninski Wed Sep 4 12:58:18 PM UTC 2024 > #10^3 leaks: 40.03 MB 40026112 pari= [7950, 1451665] > #10^4 leaks: 338.49 MB 338493440 pari= [83505, 19297360] > > import psutil,gc,sys > > from sage.all import EllipticCurve > ps = psutil.Process() > num=10**3 #10**5 // 2 > x=var('x') > def leaknf5(N=10**3): > gc.collect() > base = ps.memory_info().rss > for A2 in range(1, N): > Kn=NumberField(x^2+A2,'w') > m=Kn.class_group().order() > gc.collect() > mem = ps.memory_info().rss - base > print(f"{mem/1e6 :.2f} MB ",mem," pari=",pari.getheap()) > > leaknf5(10**4) > ==== > > [1]: https://groups.google.com/g/sage-devel/c/fWBls6YbXmw > Memory leak in |EllipticCurve([n,0]).root_number()| and problem in > algebraic geometry > -- 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/a98d82bc-313b-4b5a-8f1b-86c105089fa0n%40googlegroups.com.