Fresher4Flex
Fresher4Flex

Reputation: 38

Flash Memory Leak Problem

I have got a memory leak problem in the example below(u can download the code from the link)

http://brandonmeyer.net/projects/SuperPanelDemo/SuperPanelDemo.html

Running in Profiler:- What I am trying to do is creating new panels by selecting the Add new panel button. I am selecting option allow Close (check box).

(After creating few panels and closing these panels i could find there is memory leak with the SuperPanel class)

So my problem is how to resolve this memory leak. I tried by changing optional parameters in addEventListener, but that didn't work. Can someone provide me the solution

Upvotes: 1

Views: 1593

Answers (1)

Richard Szalay
Richard Szalay

Reputation: 84784

I think your problem is related to your bindings. BindingUtils.bindProperty is being given an your panel instance, trying it to the object graph and making it inapplicable for garbage collection.

bindProperty returns a ChangeWatcher, which you can use to unregister the binding when you are done with it. Something like the following:

var watchers : Array = [];

var panel:SuperPanel = new SuperPanel();
panel.width = 300;
panel.height = 200;
panel.minWidth = 200;
panel.minHeight = 100;

panel.title = "My Panel " + (panelContainer.numChildren + 1);
panel.addEventListener(CloseEvent.CLOSE, function(event:CloseEvent):void{
    for each(var watcher : ChangeWatcher in watchers) {
        watcher.unwatch();
    }

    event.target.parent.removeChild(event.target);
});

watchers.push(BindingUtils.bindProperty(panel, "allowDrag", allowDragCheck, "selected"));
watchers.push(BindingUtils.bindProperty(panel, "allowResize", allowResizeCheck, "selected"));
watchers.push(BindingUtils.bindProperty(panel, "allowClose", allowCloseCheck, "selected"));
watchers.push(BindingUtils.bindProperty(panel, "allowMaximize", allowMaxCheck, "selected"));
watchers.push(BindingUtils.bindProperty(panel, "allowMinimize", allowMinCheck, "selected"));

panelContainer.addChild(panel);

Also, you have not overridden the clone event in SuperPanelEvent which will cause you issues later. See this question for more details.

Upvotes: 1

Related Questions