Highlighted

Closure = memory leak on iOS?

New Here ,
Mar 10, 2016

Copy link to clipboard

Copied

Hi all! I've been troubleshooting this memory leak from hell for several months now, and figured out it seems to stem from some incredibly basic closure usage. The odd thing is that it ONLY appears on iOS (and not when using "fast packaging".)

I've posted about this in a few places, but no one seems to have a clear workaround. Does anyone else here have any insight? Or perhaps know if iOS can be a stickler about garbage collection on release builds? I keep trying the "Force Garbage Collection" button on Adobe Scout, which works flawlessly on adl, Android (both release and test builds), and iOS during fast builds. I can see activity spikes when I click the button, and numbers of other tracked objects are reduced, but certain ones refuse to go away.

Anyway, to create this leak, simply do the following anywhere the code gets ran once:

var foo:EventDispatcher = new EventDispatcher();

foo.addEventListener(Event.ADDED_TO_STAGE, function(e:Event):void { });

You would think that this would get cleaned out almost immediately by mark and sweep, but alas it doesn't. I really shouldn't have to manually remove the event listener, but even if I do like so:

var foo:EventDispatcher = new EventDispatcher();

var myFunction:Function = function(e:Event):void { };

foo.addEventListener(Event.ADDED_TO_STAGE, myFunction);

foo.removeEventListener(Event.ADDED_TO_STAGE, myFunction);


It produces the same result. I have an extra event dispatcher instance lodged in memory that I absolutely cannot get rid of. Is this expected? Is this a bug? a quirk? I made a bug report here: Bug#4126267 - Basic event listener with an anonymous function will cause memory leaks on iOS but have so far not received any feedback.

TOPICS
Performance issues

Views

258

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Closure = memory leak on iOS?

New Here ,
Mar 10, 2016

Copy link to clipboard

Copied

Hi all! I've been troubleshooting this memory leak from hell for several months now, and figured out it seems to stem from some incredibly basic closure usage. The odd thing is that it ONLY appears on iOS (and not when using "fast packaging".)

I've posted about this in a few places, but no one seems to have a clear workaround. Does anyone else here have any insight? Or perhaps know if iOS can be a stickler about garbage collection on release builds? I keep trying the "Force Garbage Collection" button on Adobe Scout, which works flawlessly on adl, Android (both release and test builds), and iOS during fast builds. I can see activity spikes when I click the button, and numbers of other tracked objects are reduced, but certain ones refuse to go away.

Anyway, to create this leak, simply do the following anywhere the code gets ran once:

var foo:EventDispatcher = new EventDispatcher();

foo.addEventListener(Event.ADDED_TO_STAGE, function(e:Event):void { });

You would think that this would get cleaned out almost immediately by mark and sweep, but alas it doesn't. I really shouldn't have to manually remove the event listener, but even if I do like so:

var foo:EventDispatcher = new EventDispatcher();

var myFunction:Function = function(e:Event):void { };

foo.addEventListener(Event.ADDED_TO_STAGE, myFunction);

foo.removeEventListener(Event.ADDED_TO_STAGE, myFunction);


It produces the same result. I have an extra event dispatcher instance lodged in memory that I absolutely cannot get rid of. Is this expected? Is this a bug? a quirk? I made a bug report here: Bug#4126267 - Basic event listener with an anonymous function will cause memory leaks on iOS but have so far not received any feedback.

TOPICS
Performance issues

Views

259

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 10, 2016 0

Have something to add?

Join the conversation