Saturday, November 6, 2010

DropDownList Memory Leak - Flex 4.1

There's a memory leak in the DropDownList in Flex 4.1 (build 4.1.0.16076). If you set the dataProvider you'll find you can't subsequently clear it from memory and it won't get garbage collected (and nor will the container etc. that houses it).

Adding the functions below provided us with a workaround (in MXML set "preinitialize" to the onPreInit function):

import flash.events.Event;

private function onPreInit():void
{
      addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
}

protected function onRemovedFromStage(event:Event):void
{
      removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
      this.dataProvider = null;
}