Serge Orlov wrote: > sonjaa wrote: > > Serge Orlov wrote: > > > sonjaa wrote: > > > > Hi > > > > > > > > I'm new to programming in python and I hope that this is the problem. > > > > > > > > I've created a cellular automata program in python with the numpy array > > > > extensions. After each cycle/iteration the memory used to examine and > > > > change the array as determined by the transition rules is never freed. > > > > I've tried using "del" on every variable possible, but that hasn't > > > > worked. > > > > > > Python keeps track of number of references to every object if the > > > object has more that one reference by the time you use "del" the object > > > is not freed, only number of references is decremented. > > > > > > Print the number of references for all the objects you think should be > > > freed after each cycle/iteration, if is not equal 2 that means you are > > > holding extra references to those objects. You can get the number of > > > references to any object by calling sys.getrefcount(obj) > > > > thanks for the info. I used this several variables/objects and > > discovered that little counters i.e. k = k +1 have many references to > > them, up tp 10000+. > > Is there a way to free them? > > Although it's looks suspicious, even if you manage to free it you will > gain only 12 bytes. I think you should concentrate on more fat > objects ;)
Sent message to the NumPy forum as per Roberts suggestion. An update after implimenting the suggestions: After doing this I see that iterative counters used to collect occurrences and nested loop counters (ii & jj) as seen in the code example below are the culprits with the worst ones over 1M: for ii in xrange(0,40): for jj in xrange(0,20): try: nc = y[a+ii,b+jj] except IndexError: nc = 0 if nc == "1" or nc == "5": news = news +1 if news == 100: break else: pass y[a+ii,b+jj] = 4 else: pass The version of python I'm using is 2.4.3 and the version of NumPy is 0.9.8 thanks again for all the help Sonja -- http://mail.python.org/mailman/listinfo/python-list