I have problem on deleting component which is created on runtime. Please help me.
heres my code in creating component
var oh: ObjectHandles = new ObjectHandles; oh.x = event.localX-xOff; oh.y = event.localY-yOff; Canvas(event.target).addChild(oh); oh.addEventListener(KeyboardEvent.KEY_DOWN,deleteSel); oh.width=270; oh.height=200; oh.mouseChildren = true; var vdo:FXVideo = new FXVideo; vdo.source = 'http://thehq.tv/wp-content/uploads/flv/funny-people-trailer.flv'; vdo.percentHeight = 100; vdo.percentWidth = 100; oh.addChild(vdo);
code in keyboard delete event
private function deleteSel(event:KeyboardEvent):void { if(event.charCode == 127) { FXVideo(ObjectHandles(event.target).getChildAt(0)).stop(); delete(ObjectHandles(event.target).getChildAt(0)); ObjectHandles(event.target).removeAllChildren(); ObjectHandles(event.target).parent.removeChild(ObjectHandles(event.target)); delete ObjectHandles(event.target); } }
after I delete the Object Handles Component(inside is FxVideo Component) the memory usage is still there. How to remove the memory allocation of component after deletion?
You need to remove the event listener, or you can add the event listener with a weak reference:
I would not recommend calling delete. Calling removeAllChildren should take care of it. Although, by looking at your code, that probably is not necessary either. Once you remove the event listener it should get cleaned up.