Jump to content

Search In
  • More options...
Find results that contain...
Find results in...
David An

Big Memory Leak

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts


	openedSkyDurRemaining / 1000,
		css: {
			width : cloud_wrapper.width()
		ease: Linear.easeNone,
		onComplete: function() {
			cloud_wrapper.find('.kr-line-timer').css('width', 0);

The code above has big memory leak and memory is increasing by 1.5G for 5~6 hours and finally chrome crashes.

If I remove this code, the memory leak issue is gone.


cloud_wrapper has some elements has event listeners defined using jquery like following:

cloud_wrapper.find('.kr-nav-arrow').on('click', function() {




But it's not the object (kr-line-timer) used for TweenLite.

Some people says I should remove listeners to fix memory leak issue. But If yes, when can I add the listeners again to accomplish my logic?


If not, how can I fix this issue?


Link to comment
Share on other sites

It's pretty tough to diagnose memory leak issues in your code by only seeing a small snippet, but my guess is that it has something to do with a closure you're creating, maybe with that onComplete. Again, impossible to say for sure without seeing the context, but I'm relatively confident there aren't memory leaks in GSAP itself. If you see evidence to the contrary, I'd be happy to look at it. 


I really wish I had a great answer for you, but we try to keep these forums focused on answering questions that are specific to GSAP itself. We don't have the manpower to offer free consulting services for troubleshooting memory leaks. Then again, if there's evidence pointing to it being a problem in GSAP itself, we definitely want to make sure the core is bug free, so we'll gladly look at the evidence in context. The best way to handle that would be to whip together a reduced test case in codepen or something so that we can see it isolated. 

  • Like 1
Link to comment
Share on other sites

I created a new pen on CodePen:

See the Pen bKCGv by davidan0926 (@davidan0926) on CodePen


You can check memory leak issue.


And I found very interesting stuff on it.


You can see the following code:

    width: 1280,
    height: 100020
When I remove setting height so left only width setting, the memory leak issue was gone.
And when I reduce the height value like height:120, memory leak was reduced as well.
When I set the height with big value like above :  height:100020, memory leak was up again.
And also when I set height to 720, in 1920 X 1080 resolution desktop, error was reduced. but in 1366 X 768 desktop, it was still buggy.
I have no idea why it's related with screen resolution.
Please advice.
Link to comment
Share on other sites

Did you know that your resume() method is getting called 3 times each loop/cycle? It also seems like you're creating a new closure each time too. Unfortunately, I just don't have time to rewrite all the code and explain how garbage collection works or how to prevent issues, but I'd encourage you to do some Googling about it - specifically how closures in JavaScript keep references to variables up the scope chain.


Also, as far as the height issue goes, that may have to do with the work that the browser has to do to render huge textures. Do you realize how massive a 1280x100,020 area is? And if you're telling the browser to animate its size, it has to recalculate all of those pixels 60 times per second. Often for the browser, that means storing those pixels in memory, shuttling them off to the GPU, and then invalidating them on the next tick, recreating them, re-uploading them, etc. 


I'm pretty confident this has nothing to do with GSAP at all. I wish I had more time to help, but we need to keep these forums focused on GSAP-specific questions. 

  • Like 3
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.