Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to free memory in SAGE?
Does anyone know how to free up memory in SAGE?

I'm not even talking so much about being able to delete a particular variable, though that would be nice too.

No, I'm talking about memory used by local variables inside functions that have already executed. Unless these values are "static", they should effectively become unusable once the function exits.


Eventually, I've got 2 GB of virtual memory being used by variables I can't even access, variables I was willing to throw away hours ago. Normally, I would just save my work to disk, quit, and restart, thus freeing up all the memory. But I had a session this morning that had been crunching numbers for hours, and I had so little memory left, I couldn't even save my work to disk!

So please, does anyone know how to free up memory in SAGE? I'm looking for some sort of garbage collector that can look at the used memory and say to itself, "Hmm, here's 2 GB of memory sitting on a stack/heap somewhere, that isn't even referenced anymore. Maybe I should free this memory..."
~ Jay Daniel Fox
For the last few months, I have continued my tradition of exiting SAGE whenever memory gets eaten up. When I need to solve a particularly large matrix system, I definitely exit and restart.

Well, I had been naively blaming the problem on SAGE, but now that I know a little better, it would appear that the problem is in python. Therefore, the real question is, how do I force python to free memory? There are lots of articles I've found in a Google search that seem to address the issue, so now I just need to find a solution. It may be as simple as a python upgrade, or it may be more complex. I did find mention of a garbage collection scheme, which I'm hoping I can access from the SAGE prompt. (One thing I did notice is that lists supposedly are handled relatively efficiently, and I tend to make use of vectors, so perhaps I need to rethink my strategy?)

For now, I'm sticking with the old standby: restarting often.
~ Jay Daniel Fox
Have you tried the following?

from gc import collect

Andrew Robbins

Possibly Related Threads...
Thread Author Replies Views Last Post
  Sage Question? rsgerard 1 5,469 05/09/2010, 11:40 AM
Last Post: bo198214
  SAGE code for computing flow matrix for exp(z)-1 jaydfox 4 11,810 08/21/2009, 05:32 PM
Last Post: jaydfox
  SAGE code implementing slog with acceleration jaydfox 4 9,800 10/22/2007, 12:59 AM
Last Post: jaydfox
  Complete SAGE code for tetration eyu100 4 8,717 10/18/2007, 03:55 AM
Last Post: jaydfox
  How to force precision in SAGE? jaydfox 2 7,138 08/18/2007, 11:08 PM
Last Post: jaydfox

Users browsing this thread: 1 Guest(s)