all groups > flash actionscript > december 2004 >
You're in the

flash actionscript

group:

variables in keyListener


variables in keyListener lancelott
12/18/2004 5:33:19 PM
flash actionscript:
if I execute a function in frame 1: myFunction; myFunction() { var p=100;
trace(p); } It's clear that p will be destroyed when the funcion is finished
since it's local variable. But the complicated thing comes when there is an
keyListener in function: myFunction() { var p=100; var myListener=new
Object(); myListener.onKeyDown=funtion() { trace(p); }
Key.addListener(myListener); } in this case, p will stay as long as the
listener does't get deleted. If I delete the listener by
Key.removeListener(myListener), do I need to manually delete p?
Re: variables in keyListener JKringen
12/18/2004 5:41:59 PM
I think p should be destroyed when that listener is done, but I could be wrong.
There's not really much for garbage collection in Flash. I've noticed on my
huge flash projects, that even classes that are initlaized in local variables
still remain in memory even after the movieclip that the variable was created
on is destroyed, so who knows! haha. I've had to create manual garbage
collection functions in many of my classes because of this, so deleteing p
isn't a bad idea if you find that it still exists. But I think it should be
taken care of automatically.
AddThis Social Bookmark Button