Memory leak?


(Oplek) #1

I have this python script, which contains a class object, with a few functions inside of it. It has multidimensional lists inside. It passes 3-element lists around, and calculates with them, but nothing more complex.
I’m running 2.23 on XP BTW

My issue is, As I run the script over and over, such as over the course of an animation, something eats away at my memory (only when I use this particular script). I have XP’s task manager open, and I’m watching the virual memory counter (PF), as the script runs. My VM starts at about 90-95 megs, and after about 200 iterations, its up to 150 megs and climbing. It starts getting to a point where my computer hangs, churning away at the harddive.

Does anyone have any experience with this behaviour?


(stephen2002) #2

no, I have not had that particualr problem with a python script.

I do belive that the variables stay in memory when the script exits. Try doing this line at the end of the script:

sys.stdout.flush()

Which clears out something. It really clears up a lot for my scripts when I keep wondering why it isn’t working right.

Also, sub-surfs don’t get cleared, and will slowly eat memory as it renders.

Also, does your script keep adding to those lists? It dosn’t make sence that your HD would be grinding away unless it was needing to access all of that old info.


(Oplek) #3

I tried the flush() command, but to no effect.

I don’t have anything that increases the size of the lists. I made a function to check for that, and the internal main multidimensional list stays the same size.

I’m not subsurfing anything either.

I thought that calling the script which had the class definition in it over and over was doing something, so I moved the runtime script material to a seperate script file, to no effect.

<font size=-1>[ This Message was edited by: Oplek on 2002-03-23 09:22 ]</font>


(theeth) #4

Are you using the Blender.NMesh.GetRaw() function?

There’s a memory leak in it. The solution would be to move only call it if the object is not in memory or reuse the one already there.

Martin


(Oplek) #5

Actually, I am. I have a function that uses it to update the main mesh (Im editing the position of the vertices).
I’m not sure I understand your solution. Here’s what I have:

def Matrix_to_Mesh(self): #part of the class
Flag_Mesh = Blender.NMesh.GetRaw(“Flag”)
for y in range(self.YRES):
for x in range(self.XRES):
for in range(3):
Flag_Mesh.verts[y*(self.XRES)+x].co[i]= self.Matrix[y][x][0][i]
Blender.NMesh.PutRaw(Flag_Mesh,“Flag”)
Blenmder.Redraw()


(Oplek) #6

Alright, I got it.
Instead of calling the NMesh.Getraw() function each time in the matrix_to_mesh function, I set “global Flag_Mesh” and called it once in the script where the class is(except externally to the class), and ran the runtime script as usual. NMesh.Getraw() was thereupon run only once, and no more memory gobbling! YAY!

Thanks, guy

<font size=-1>[ This Message was edited by: Oplek on 2002-03-23 12:29 ]</font>