Jump to content
Search Community

TimelineMax and (avoiding) memory leaks

cerulean test
Moderator Tag

Recommended Posts

Is there anything to be aware of when creating many timelines as far as making sure they are disposed of properly?

 

I've got TImelineMax's that, on completion, create other timelines (a sort of onComplete recursion) -- so that each timeline, although tweening the same objects, can have new random variables.

 

I assume that the old timelines will be garbage collected.  I call .kill() on them just to be sure, but of course they've already completed.

 

While I'm at it, may I ask a probably stupid basic AS3 question?  I've got several objects I'm tweening with my TimelineMax's. If I do something like this:

 

 

 

private var _tl1:TimelineMax;
private var _tl2:TimelineMax;
 

 

 

and then I have a call like

 

 

 

function makeANewTimlineMax($tl:TimelineMax,$tweenClip):void {
    var newTL = newTimelineMax.to($tweenClip,1,{onComplete:makeANewTimelineMax,onCompleteParams:["{self}"]});
// private variable referencing $tl = newTL ???
}
 

is there any way to access the _variable_ to which the TimelineMax _was assigned_?  That is, I don't know whether the timeline was assigned to _tl1 or _tl2 but I want to change the values in those variables to point to the newly created timeline.

 

 I think not -- I mean we're passing a reference to a timeline, which is, if this were C, a pointer to some memory, and _tl1 and _tl2 just hold the value of that pointer.  But there's no way to change _tl1 and _tl2 then, because there's no non-kludgy way to track back from the reference passed to my function to any number of possible variables which _also_ hold that reference, right?  I think I've answered my question, but it smacked my mind, trying to figure this out. —  In the end I did something like this, which worked fine -- the reason I'm keeping a reference to the tl's somewhere is so that later I can stop them if I need to.

 

 


private var _myClip1:MovieClip
private var _myClip2:MovieClip

function makeANewTimlineMax($tweenClip:MovieClip):void {
    var newTL = newTimelineMax.to($tweenClip,1,{onComplete:makeANewTimelineMax,onCompleteParams:[$tweenClip]});
   $tweenClip.timeline = newTL;
}
 
Link to comment
Share on other sites

You shouldn't need to do anything special to make timelines eligible for garbage collection, except the normal stuff like if you're keeping a reference somewhere that's a persistent variable, you should null it. But yes, we've put a lot of effort into making sure things are protected from gc when necessary, and released for gc when appropriate, all automatically. Let us know if you run into a gc problem that you thing is due to GSAP somewhere. 

 

As far as tracking the variables, I didn't quite follow your description, but maybe this will help: if you declare your variables outside the function and assign them inside the function, you can still access them elsewhere within scope. Kinda like:

 

private var _tl1:TimelineMax;

function makeANewTimlineMax($tl:TimelineMax,$tweenClip):void {
    _tl1 = new TimelineMax.to($tweenClip, 1, {onComplete:makeANewTimelineMax, onCompleteParams:["{self}"]});
}

You might also want to look into Dictionary objects, as they allow you to associate objects with other objects easily:

 

var _lookup:Dictionary = new Dictionary();

function makeANewTimlineMax($tl:TimelineMax,$tweenClip):void {
    _lookup[$tweenClip] = new TimelineMax.to($tweenClip, 1, {onComplete:makeANewTimelineMax, onCompleteParams:["{self}"]});
}

//then later...
var tl:TimelineMax = _lookup[$tweenClip];

Does that help?

  • Like 1
Link to comment
Share on other sites

Yes, thanks.  Of course, the variable remains in scope!  I don't know why I was making it so hard on myself — I will blame it on switching back to AS3 after several months of javascript (although it's the same thing in JS, no?).  Yes, that must be it. :->

 

Oh, now I remember — it was that I didn't know _which_  class variable I would be modifying, so I wanted to pass that as a parameter to the function. That's why I couldn't simply assign it to the class variable.  My convoluted question was about that -- how to pass a variable name as a parameter. In any case, the dictionary will work fine.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...