garbage collection - Python: cracking the gc enigma -


i trying understand gc because have got large list in program need delete free badly needed memory. basic question want answer how can find being tracked gc , has been freed? following code illustrating problem

import gc old=gc.get_objects() a=1 new=gc.get_objects() b=[e e in new if e not in old] print "problem 1: len(new)-len(old)>1 :", len(new), len(old) print "problem 2: none of element in b contain or id(a): ", in b, id(a) in b print "problem 3: reference counts insanely high, why?? " 

imho weird behavior isnt addressed in docs. starters why assigning single variable create multiple entries gc? , why none of them variable made?? entry variable created in get_objects()?

edit: in response martjin's first reponse checked following

a="foo" print in gc.get_objects() 

still no-go :( how can check being tracked gc?

the result of gc.get_objects() not tracked; create circular reference otherwise:

>>> import gc >>> print gc.get_objects.__doc__ get_objects() -> [...]  return list of objects tracked collector (excluding list returned). 

you not see a listed because references 1 of low-integer singletons. python re-uses same set of int objects values between -5 , 256. such, a = 1 not create new object tracked. nor see other primitive types.

cpython garbage collection needs track container types, types can reference other value because thing gc needs break circular references.

note time python script starts, automatic code has been run. site.py sets python path example, involves lists, mappings, etc. there memoized int values mentioned above, cpython caches tuple() objects re-use, etc. result, on start-up, 5k+ objects alive before 1 line of code has started.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -