Solved

Using Private Variables To Avoid Garbage Collections

Posted on 2008-10-15
5
385 Views
Last Modified: 2013-11-11
Garbage collection is occasionally recycling my tween variables and thereby killing my tween.

I was wondering if it would be possible to use a private array of variables that I reset after the tweens are completed, since I believe garbage collection does not apply to private variables (please correct me if I am wrong so far).  However, i seem to be having trouble with the private variables.

here is my code on this.  really the slideBlade function is the only revelant part, but I thought I would also include the part where it is called, since it runs four times in a row.  (bladeTotal is always equal to 4)
public function slideBlade(which, pos, bladeTotal) {

			

			trace(bladeTotal+": bladeTotal");

			

			

			var tween:Tween = new Tween( which, "x", Regular.easeInOut, which.x, which[pos], .6, true);

			

		}

		//--------------------------------------------------------------------------------

		public function bladeEngine(which) {

			removeThumb(null);
 

			if (this.currentBlade == which) {

				for (x = 1; x <= bladeTotal; x++) {

					whichBlade = this["blade" + x];

					slideBlade(whichBlade,"closePos",bladeTotal);

				}

				which.blade.gotoAndStop(1);
 

				this.currentBlade = null;

				this.bladeNumber = 0;

			} else {

				if ( this.currentBlade != null) {

					this.currentBlade.blade.gotoAndStop(1);

				}

				if (which.bladeNum < this.bladeNumber) {

					for (x = which.bladeNum + 1; x <= bladeTotal; x++) {

						whichBlade = this["blade" + x];

						slideBlade(whichBlade,"closePos",bladeTotal);

					}

				} else {

					for (x = 1; x <= bladeTotal; x++) {

						if (x <= which.bladeNum) {

							whichBlade = this["blade" + x];

							slideBlade(whichBlade,"openPos",bladeTotal);

						}

					}

				}

				this.currentBlade = which;

				this.bladeNumber = this.currentBlade.bladeNum;

				this.currentBlade.blade.gotoAndStop(2);
 

				if (this.currentBlade == which) {

					buildTree( this.bladeNumber, this.currentBlade.bladeName, "", "" );

				}

			}

		}

Open in new window

0
Comment
Question by:walker6o9
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:asaivan
ID: 22727054
Yeah, just create a private var outside your function block, e.g.

private var tween:Tween;

then in your function:

tween = new Tween(...);

That should stop your tweens from being killed.

Is that not working for you?
0
 
LVL 4

Expert Comment

by:MattKenefick
ID: 22731630
Put them all in an array / object container. Pop/shift them as you complete them or just dump the container when they're all done.
0
 
LVL 1

Author Comment

by:walker6o9
ID: 22733397
MattKenefick-
I'm sorry, I'm not sure how that would work?  Do you kill them after they run?  Can you show me how that would work?
0
 
LVL 4

Accepted Solution

by:
MattKenefick earned 500 total points
ID: 22733595
This is a small article with links to others and includes examples.


http://www.bigroom.co.uk/blog/object-pool-class

( Better to not re-invent the wheel when it has already been said =] )
0
 
LVL 1

Author Closing Comment

by:walker6o9
ID: 31506560
BRILLIANT!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now