CreateJS / html5ads

An in-depth white paper on building HTML5 advertising with CreateJS and Flash Pro. Includes supporting materials, sample banner ad, and helper classes.
72 stars 58 forks source link

Memory leak when exporting html5 canvas from Flash CC 2015 #1

Open dvhoafrontflip opened 8 years ago

dvhoafrontflip commented 8 years ago

Hi guys,

I'm using Flash CC 2015 publish a Html5 banner, open it on chrome for 30 minutes and the huge memory waste on my PC. I had tried to reproduce this problem on both chrome, firefox latest version and the same things.

Memory leak in 2 context:

  1. As you can see in Chrome task manager, memory still increase while the tab is in focus. memory leak
  2. Switching to another tab, the banner's still eating more memory. I tried to add more 25 banners by loading into 25 iframes in a single page and final result memory was increased so fast.

To Fix it: An workaround for context 2 by edit the publishing html file and adding some small function to listen "visibilitychange" event when user switch tab and stop the ticker when tab lost focus:

var isActive = true;

function onStopAnimation() {
    createjs.Ticker.removeEventListener("tick", stage);
}

function onStartAnimation() {       
    if(isActive == true) {              
        createjs.Ticker.addEventListener("tick", stage);
    }else {
        onStopAnimation();
    }
}

function handleVisibilityChange() {
    if (document.hidden) {     
        isActive = false;
        onStopAnimation();
    } else {            
        isActive = true;
        onStartAnimation();
    }
}

document.addEventListener("visibilitychange", handleVisibilityChange, false);   

For context 1, it looks like the ticker still running and redawn the object? any tips for how to work around when we public html with flash cc 2015

Thanks, Hoa

sveg-pl commented 7 years ago

Hi @dvhoafrontflip I know it's been almost a year yet the Flash CC 2015 has changed to the Animate CC and I wanted to test your issue. I've run html5ads recently and the leak is NOT present.

I've published the "garyad" using Animate CC 2015.2 with one instance of the ad and also with 5 instances using iframes, just like you did. The memory footprint rises slowly and after some time it stays or drops a bit. With one instance of the ad, the memory footprint starts at ~22 MB and grows to ~50 MB (even without the tab being in focus), so it indeed looks like a leak, but then the memory stays around this value.

What is more important – I even used old "garyad" files straight from the html5ads ZIP (without any compilation or publishing), coming from the Flash CC as I presume. Probably the same that you've used, as they were not changed since October '15 and I also did not observe the leak resembling that one of yours. This could mean that the bug was in fact caused by some kind of JS interpreting error...

Best regards, SVEG