Saturday, November 6, 2010

DropDownList Memory Leak - Flex 4.1

There's a memory leak in the DropDownList in Flex 4.1 (build 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):


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;

No comments: