Ask Your Question
0

Explicitly clean all memory usage

asked 2019-06-05 17:45:28 +0200

imnvsh gravatar image

updated 2019-06-05 17:46:04 +0200

class State(): def __init__(self): self.value = []

state0 = State()
state0.value = range(10^8)

At this point, a huge memory is located. After processing state0.value, I set it back to empty to continue another process.

state0.value = []

However, the memory is not fully cleaned. Therefore, I cannot continue another process due to my limitation of memory on my computer, and I have to close Sagemath 8.4 to get back to the fresh memory. It is better to iterate, instead of using memory like this; however, I hope that an explicit memory clean exists in Sagemath. Besides it, I use range(10^8) to illustrate my actual 10^8 data in type of set to ease the understanding, so please do not support on re-formulating this usage of range.

edit retag flag offensive close merge delete

Comments

Perhaps reset(state0.value)?

Juanjo gravatar imageJuanjo ( 2019-06-05 19:35:26 +0200 )edit

using python2 or python3 ?

FrédéricC gravatar imageFrédéricC ( 2019-06-05 20:06:29 +0200 )edit

I think my Sagemath 8.4 is still in Python 2.7

imnvsh gravatar imageimnvsh ( 2019-06-06 20:36:08 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2019-06-05 20:11:46 +0200

nbruin gravatar image

This is really a question about python memory management. If I'm not mistaken, python may under certain conditions give memory back to the OS, but claiming memory from the OS is quite an expensive operation, so for efficiency reasons, I'd expect python to be rather reluctant at doing so: most of the time it's better to keep a hold of the memory for reuse later.

Another thing to be aware of: just because you delete one reference to the data structure doesn't necessarily imply the data structure can be garbage collected. It could be that the IPython history buffer holds a reference to it or that there's a debugging dataframe lying around that is still referencing the data structure.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-06-05 17:45:28 +0200

Seen: 664 times

Last updated: Jun 05 '19