From: Beracah Y. <be...@MI...> - 2010-05-09 23:33:47
|
Hi all, Having visited the site and the buglist, which appears to be old/not in use anymore, I figured that I would just email this list. I'm concerned about a possible memory leak, which I've traced down to be either the way vpython keeps numpy ndarray position objects around or numpy failing to deallocate them properly. I'm using windows, so I'm assuming that the vpython lib on windows is statically linked since the main page didn't tell me anything about downloading numpy. I create and destroy hundreds of thousands of objects in the vpython window lifetime, and I notice that the memory slowly grows until the application crashes after a day or so. I made a test script, that only creates objects in the window, then deletes them over and over, and I found the long-term memory use/growth to be related linearly to the .pos attribute. For instance, a curve with 20 points leads to unreleased memory that grows 10x as fast as curves with only 2 points. Similarly, if I assign the .pos attribute as a numpy ndarray directly, the leak grows twice as fast as if assign the individual xyz values. I've upgraded my numpy without any change. Also, in aug 2009, numpy users of v1.3.0 noticed a memory leak in the ndarray subclass: http://www.mail-archive.com/num...@sc.../msg19776.html I included the test code here -- please let me know if I've just missed something totally obvious about the way the objects/positions should be deallocated. Thanks! Beracah //------------------------------------------------------ import visual.crayola import visual import random import thread import sys import time win=800 L = 16 # should correspond to the radius of the smallest tree width=1000 height=700 scene = visual.display(title="3D Relational Viz Engine", width=1000, height=700, range=2*L, forward=(0,-.2,-1)) scene.fullscreen = 0 scene.autocenter = 0 scene.autoscale = 0 scene.userzoom = 1 rootframe = visual.frame() globjects = [] # this is the test; loop infinitely creating objects # drestroy them every X times # pretty stuff. def rotateit(): global rootframe ir=0 while 1: if (ir % 120 ) == 0: x = 1 if (random.random() < .1) else 0 y = 1 if (random.random() < .1) else 0 z = 1 if (random.random() < .1) else 0 z = 1 if ((x + y + z) == 0) else z # print (x,y,z) # chang direction randomly direction = -1.0 if (random.random() < .1) else 1.0 speed = 4.0 if (random.random() < .1) else 1.0 if rootframe: rootframe.rotate(angle=(speed*direction*visual.pi/2160.), axis=(x,y,z), origin=(0,0,0)) # rootframe.rotate(angle=visual.pi/360., axis=(1,0,0), origin=(0,0,0)) ir+=1 #print ir # rotate by Z every hundred or so. if (ir % 5) == 0: rootframe.rotate(angle=(speed*direction*visual.pi/1080.), axis=(x,y,z), origin=(0,0,0)) visual.rate(90) rotatethread = thread.start_new_thread(rotateit, ()) totalobjects = 0 # for i in xrange(100): while 1: # print len(globjects), totalobjects if 0: # len(globjects) % 2 == 0: globjects.append( visual.label( pos=( random.uniform(-10,10), random.uniform(-10,10), random.uniform(-10,10)), # text=str(random.uniform(0,100000000)) + str(random.uniform(0,100000000)) + str(random.uniform(0,100000000)), # memory is DEF a f(string length) text = 'a', # now lets see if somehow the number of objects is not being freed... frame=rootframe, linecolor=(255,0,0), height=10, opacity=.125, border=0, box=0, color=(255,0,0)) ) else: globjects.append( visual.curve( pos=[ (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)), (random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)) ], color=(0,0,255), frame=rootframe)) # time.sleep(1.0) if len(globjects) >= 1000: totalobjects += len(globjects) print totalobjects for i in reversed(xrange(len(globjects))): globjects[i].visible = 0 # globjects[i].remove(0) for p in xrange(len(globjects[i].pos)): # print p, type(globjects[i].pos[p]) # print point "" del globjects[i] del globjects globjects = [] visual.rate(1000) |