Re: Memory usage

25 views
Skip to first unread message

switzel

unread,
Feb 18, 2013, 10:00:23 AM2/18/13
to sage-s...@googlegroups.com
Hi,

I found some answers myself. The memory usage can be found out with

get_memory_usage()

and there is a garbage collection that can be called manually via

import gc
gc.collect()

so I could do something like

import gc
i=i+1
if (i%10000==0):
    if get_memory_usage()>3000:
        gc.collect()

but shouldn't there be a more "automatic" way? Thanks!

Best,
Stefan

On Monday, February 18, 2013 2:17:16 PM UTC+1, switzel wrote:
Hi,

I am wondering about the following phenomenon: I have a list "interrels" of polynomials in many variables and a list "potential_sols" of potential solutions and I am using the following code to check which are actually solutions (roots). I use the following code

sols=[]
for psol in potential_sols:
    for interrel in interrels:
        if interrel(*psol)!=0:
            break
    else:
        print(psol)
        sols.append(psol)

I am not surprised (under my circumstances) that this takes long, though actually it wasn't that bad at first. What surprises me is that it uses huge amounts of memory. The actual data don't take that much memory and the code just linearly runs through all possibilities so it practically shouldn't need any extra memory at all (at most another copy of potential_sols). But instead it had filled the 4 GB physical memory plus 2 GB swap when I canceled it (of course by that time it also was terribly slow, just because of all the swapping). This seems to suggest memory leaks.
Is there any way I could check what part of sage (and which data structures) use how much memory? Are there any known issues about memory leaks related to polynomial rings over finite fields? Is there a garbage collection I have to call manually?
Thanks for any help!

Best,
Stefan

Simon King

unread,
Feb 18, 2013, 11:04:24 AM2/18/13
to sage-s...@googlegroups.com
Hi,

On 2013-02-18, switzel <stwi...@gmail.com> wrote:
> so I could do something like
>
> import gc
> i=i+1
> if (i%10000==0):
> if get_memory_usage()>3000:
> gc.collect()
>
> but shouldn't there be a more "automatic" way? Thanks!

Garbage collection *is* automatic, and there is no need to call it
manually. And actually it wouldn't help to call it manually.

What Sage version are you using? Namely, the most recent version
(or perhaps beta version?) contains several fixes for memory leaks that come
from an over-eager cache.

Best regards,
Simon

Reply all
Reply to author
Forward
0 new messages