0

I've searched and couldn't find any good answer. Let's say that I have some list that have thousands of entries or something else that consumes a lot of memory. Is it good idea to change this list/etc. value to 0...

oldlst = 0

...if it's no longer needed (or won't be updated in a very long time) or should I leave it alone in program. Or maybe there is better way to handle this.

Example:

L = range(50*2000*1000)
raw_input("Press Enter")
L = 0
print L

When I run this command I use 838.1 MB of RAM after pressing enter and changing L to just 0 I release some of the memory taken

JeremyK
  • 147
  • 1
  • 1
  • 10
  • 1
    That will decrement the list's reference count, so it can be garbage collected if nothing else has a reference to it. However it's not clear why you think you need to do this; could you instead use e.g. scoping more sensibly so that its references are released when you've finished using it (e.g. at the end of a function)? Could you provide a more concrete [mcve] of the problem you're trying to solve? – jonrsharpe Jun 15 '16 at 15:12
  • use del oldlst` :-) – aliva Jun 15 '16 at 15:13

1 Answers1

-3

You need to think on releasing memory rather than making list to 0 once not required.

Please refer

Community
  • 1
  • 1
Elixir Techne
  • 1,848
  • 15
  • 20