The discussion you found about a memory leak referred to a bug that
was fixed last March. From the "recent developments" section of
vpython.org: 2011-03-01 Visual 5.51: Fix memory leak on Windows and
Mac.
You've found a different memory leak, one that has not previously been
reported. The leak that was fixed was a bug in rendering the scene on
Windows and Mac, with the effect that setting object.visible = False
eliminated the leak. Setting object.visible = False in your program
doesn't make any difference: the leak is still there.
Thanks much for reporting this. At the moment I don't know what is
causing the leak. I note that commenting out make_normals, smooth, and
make_twosided has no effect on the leak. The leak is associated with
self.model.pos = self.vertices (but, I repeat, independent of whether
the faces object is visible or not). I also note that if one executes
m.Draw just once (putting a break at the end of the while loop), there
is no leak, confirming that the leak is not associated with the
repeated rendering that is automatically performed, unlike the case
with the old leak.
Since the problem is somehow associated with the statement
self.model.pos = self.vertices, I made a version of your program that
allocates once and for all the pos array, then assigns values to the
pos array rather than constructing a vertices array first. The
following program does not show a memory leak. This of course leaves
open the question of why there is a leak when one assigns an array to
faces.pos.
from visual import *
class Model:
def __init__(self):
self.frame = frame()
self.model = faces(frame=self.frame, color=color.cyan, visible=True)
class Mesh (Model):
def __init__(self, z):
Model.__init__(self)
self.length = (z.shape[0]-1)*(z.shape[1]-1)*6 # length of one-sided data
self.model.pos = zeros( (2*self.length,3), float ) # space for
two-sided data
def Update(self, xvalues, yvalues, zvalues):
points = zeros( xvalues.shape + (3,), float )
points[...,0] = xvalues
points[...,1] = yvalues
points[...,2] = zvalues
p = 0
for i in range(zvalues.shape[0]-1):
for j in range(zvalues.shape[1]-1):
self.model.pos[p ] = points[i,j]
self.model.pos[p+1] = points[i,j+1]
self.model.pos[p+2] = points[i+1,j+1]
self.model.pos[p+3] = points[i,j]
self.model.pos[p+4] = points[i+1,j+1]
self.model.pos[p+5] = points[i+1,j]
self.model.pos[self.length+p ] = points[i,j]
self.model.pos[self.length+p+2] = points[i,j+1]
self.model.pos[self.length+p+1] = points[i+1,j+1]
self.model.pos[self.length+p+3] = points[i,j]
self.model.pos[self.length+p+5] = points[i+1,j+1]
self.model.pos[self.length+p+4] = points[i+1,j]
p += 6
self.model.make_normals()
self.model.smooth()
x = arange(-1,1,2./20)
y = arange(-1,1,2./20)
z = zeros( (len(x),len(y)), float )
x,y = x[:,None]+z, y+z
m = Mesh(y)
i = 0
dt = 0.05
while True:
m.Update( x, (sin(x*pi + i*dt)+sin(y*pi + i*dt))*0.2, y )
i += 1
rate(100)
Bruce Sherwood
On Fri, Jul 22, 2011 at 3:15 AM, Wojtek Frycz <woj...@gm...> wrote:
> Hi!
> I'm new to VPython project but I found a memory leak. There was something
> mentioned about this problem before. I found it here:
> http://sourceforge.net/mailarchive/forum.php?thread_name=AANLkTim8RL8kjW0%3DSK%2B9f-2A5TCQv6wAu9aTpBmisbNS%40mail.gmail.com&forum_name=visualpython-users.
> But unfortunately I didn't find the solution.
|