Share Posted January 22, 2018 Hi, I'm using TweenMax with PIXI.js to tween positions of objects... I have lots of objects being spawned, tweened and then destroyed. When I just create an object and then destroy it and make it null, it gets removed from memory (using Chrome heap snapshot to check). If I create the object then tween it, then call kill() on the tween and destroy my object, it the object hangs about in memory. Its seems that TweenMax is keeping reference to the target I set the tween on, even after I have called kill() on the tween, in some kind of lookup dictionary in TweenMax. So I'm building up a lot of objects in memory that I can't clear, which is a big problem. Is there a way to flush this cache of objects in TweenMax when I kill a tween? Thanks Rich Link to post Share on other sites
Share Posted January 22, 2018 For performance reasons, GSAP hangs onto a reference for up to about 2 seconds (max). You should see them released regularly (just not immediately). Link to post Share on other sites
Author Share Posted January 22, 2018 Thanks for the response. I thought this but for some reason in my test the objects just hang around indefinitely and build up in memory. Could be something to do with the dev tools / what I'm logging to console, so I'll build a proper test to post here. For now I am manually removing the target from _internals.tweenLookup when I kill() and its back to using no memory again. Thanks 2 Link to post Share on other sites
Author Share Posted January 23, 2018 Hi I've tested again it was something else causing the issue, my bad. The objects were being cleared from GSAP after 2 seconds. Is there a way to customise or disable this cache? 1 Link to post Share on other sites
Share Posted January 24, 2018 I'm curious why you'd want to disable that. It's implemented currently so that it maximizes performance. I believe you could tweak it by adjusting the TweenLite.autoSleep value lower. Does that help? 3 Link to post Share on other sites
Author Share Posted January 24, 2018 OK thanks. I suppose the reason is also me being curious. More so in cases with a game engine where you might be creating hundreds of new objects per second or testing memory / debugging its just useful to know, but I can't think of a real case where I'd be creating hundreds or tweens like that. Thanks though! Link to post Share on other sites
Share Posted January 24, 2018 When I need to create and tween hundreds of new objects every second, I usually use an object pool so I can reuse them. When respawning, I call invalidate to adjust the start and end values for any tweens that need to be updated. Yes, you sacrifice memory, but performance will usually be better as garbage collection will happen less often. 4 Link to post Share on other sites
Author Share Posted January 24, 2018 Thanks OSUblake yes thats what I was thinking, in a real case you would pool... I do think this hanging on to Tweens / autoSleep should be in the docs somewhere though, not seen it mentioned anywhere? Link to post Share on other sites
Share Posted January 24, 2018 This is the first time I've ever heard about autoSleep. I don't know why it's not documented, but I had to go look in the source code to see what it does. 1 Link to post Share on other sites
Share Posted January 24, 2018 Yeah, sorry about that but sometimes we add some features that we intentionally leave undocumented because we're not sure how useful they'll be in real-world situations, so we kinda leave the door open and see how many times it comes in handy for real-world situations. autoSleep is one of those that almost nobody seems to need or care about 1 Link to post Share on other sites
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now