Skip to main content
May 14, 2008
Question

Vars and memory cleanup

  • May 14, 2008
  • 8 replies
  • 456 views
in a method I am creating dynamically created vars based on the 'frame' + _currentframe set keep track of if the user has been on the frame before.

It is working on and off. By using trace statements I can see that the var is created and set then when i navigate away and back it is still there but if i take a little time navigating away then back the var gets recreated because it does not see it.

My only thought on this is that garbage collection is occuring. Is this correct? Any thoughts?
This topic has been closed for replies.

8 replies

kglad
Community Expert
Community Expert
May 15, 2008
you're welcome.
May 15, 2008
I just found the issue.

Something about Flash I dont like. If you use ActionScript to place items on the stage, then when you try and find references to code such as my variable and it exists in a library item, Flash will NOT list the item in the Movie Explorer.

Only items that where manually placed on the Stage will show up in the listing for the Movie Explorer.

I did have a reference to the variable that was = and not ==.

Thanks a bunch kglad :)
kglad
Community Expert
Community Expert
May 15, 2008
you're welcome.
May 15, 2008
Thanks for the clarity on the gc feature. I'm a bit baffled as my situation is none of the ones you have listed. The method that is called is on the main stage timeline and spans over all frames.

I'll have to play around a little more with it and if all else fails try a different way of dealing with this. Thanks again kglad.
kglad
Community Expert
Community Expert
May 15, 2008
variables are not gc'd by flash unless they are local to a function/method and prefixed with var in a declaration (which you've just stated doesn't exist) or they are local to a timeline/movieclip that is removed.
May 15, 2008
kglad,
Thanks for looking at this issue with me.

As for additional code, there is none that makes any reference to the variable. I check and see if it exists in an if condition as posted above if it does not exists then it will lets say call a method playA(). Else it will call a method showButDontPlayA().

Nothing else makes a reference to it. So I was thinking that because its being created inside of a method it gets cleaned up right away once im out of the method.

Thinking of creating an array var at the top and then the method call can just add to the array since im keeping track of frames that are viewed. I dont think a var created at the top level can be cleaned out since it was not dynamically created.

Do you know of any links to information on variable persistence that you know of that are direct and not dozens of pages of blah blah blah information?

thanks again.
kglad
Community Expert
Community Expert
May 15, 2008
there's no problem with the code you showed. if there's other code where your variable appears and it's not on the right-hand-side of an assignment operator (=), that may be the problem.
kglad
Community Expert
Community Expert
May 14, 2008
show the code you're using to set your variable.
May 15, 2008
Note the following code resides inside of a method.