What happens to data when a variable is reassigned?

I’m assigning global variables to my number buttons so I can get Button.val to get the current value of the number button. Every time the redraw function triggers, the buttons get created again (found this example code in the Blender/Python docs). So what happens to the button that was last assigned to the global variable? Does Python know to free that memory, or does it do the same thing as deleteing objects (where the nmeshes stay around until you reopen the .blend)?

ie. every Redraw I do my buttons drawing like:

myglobalnumberbutton=Number(…)

If if doesn’t free the memory, how else can I do this with number buttons? Is there a way to get a pointer to the number button from the event number?

the memory is freed unless blender has a bug in it

[which would probably have been fixed by now]

Thanks, z3. I figured it had to work that way, but I couldn’t find info explicitly stating that. I don’t quite understand why we don’t get a Button.Redraw() instead of creating them and destorying the old ones every time the redraw function gets called.

import Blender
from Blender.Draw import *
from Blender.BGL import *

numberbutton = Create(0.)

def gui():
	global numberbutton
	numberbutton = Number("bla: ", 4, 10, 180, 100, 20, numberbutton.val, 0., 5.)

...

i guess u use something like this? then the memory should be reused/overwritten coz u use the same name for the button object

Yeah, that’s what I’m talking about. It’s not entirely clear from the Python and/or Python/Blender docs that reassigning a variable will delete the old object. I know this won’t fly in C, but will, for example, in Foxpro. I can’t find documentation that addresses this issue specifically.

i remember reading that py2.4 has a fix that frees memory, eg when you copy large lists and later delete some the memory will be freed -> i guess that did not happen in py2.3

if you want to be sure you might want to check it: just create some kind of loop/timer to trigger the redraws for a couple of buttons every second. if after half an hour blender is as fast as at the beginning you could be sure python is not a memory eater :smiley:

Yeah, that’s a good idea. I was thinking about doing that - I figure I’d just watch the memory meter to watch it in real time if keeps growing. Thing is, it could be something else not related to Python, per se, that’s doing it. I have no real way of knowing unless I know what it’s supposed behavior is. So how to we find out for sure? I need one of those yellow smiley faces for a guy with one hand on his chin thinking/wondering about something. :stuck_out_tongue: