Debugging reference counts in python/C

2006-08-30 Thread karmadharma
Hello everybody I am trying to make sure that my (non trivial) C module is cleaning up properly after itself, and consequently I've built python with --py-debug which, besides allowing me to use certain functions, it also prints the reference count at the end. I am finding, however, that the refe

Re: Reference Counts

2006-05-19 Thread Tim Peters
[raghu, on Heiko Wundram's test program: import sys x = {} i = 0 def test(): global x, i x[i] = "test" i += 1 del x[i-1] # Properly clean up x. for j in xrange(1): print "Before", j, ":", sys.gettotalrefcount() test() print "After", j, ":", sys.gettotalrefcount() ] > Hm

Re: Reference Counts

2006-05-18 Thread raghu
Hmm... I tried the gc.collect(). It aint helping. The reference count still keeps growing till 5 after it which it drops. As you said, it is not gonna hurt right away. The only downside in that mysterious up and down thingie is that , we could get to a wrong conclusion about a leak, if we ran the

Re: Reference Counts

2006-05-18 Thread Heiko Wundram
e issues). That's why you see an increase in reference counts, until the interpreter calls the garbage collector, which frees the object cycles, and so forth. I don't exactly know what the "magic constant" (i.E. number of byte-code instructions between subsequent runs of the ga

Re: Reference Counts

2006-05-18 Thread raghu
Heiko, Thanks for the explanation. I understood the idea of 1 being interned. Also I understood the globals vars having a reference in the internal dict. I ran the "leaky" version of the program and yes...it showed a progressively increasing totalrefcount as below. Before 0 : 16579 After 0 : 1658

Re: Reference Counts

2006-05-17 Thread Heiko Wundram
Am Donnerstag 18 Mai 2006 08:28 schrieb raghu: > #!/usr/bin/python > > import sys > global a > > print "Total Reference count at the start =",sys.gettotalrefcount() > a=1 > print "a ref count =",sys.getrefcount(a) > b=a > print "a ref count =",sys.getrefcount(a) > > del a > del b > > print "Total R

Reference Counts

2006-05-17 Thread raghu
Hi All, I am a new user of Python and am having a bit of problem understanding the Reference counting and memory leakage issues. Requesting help from experienced users I wrote the following simple program. #!/usr/bin/python import sys global a print "Total Reference count at the start ="