talhatima / flexlib

Automatically exported from code.google.com/p/flexlib
1 stars 0 forks source link

Memory leak in MDIManager on caching MDIManagerEvent #184

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Make an application that dynamically adds and removed MDIWindows to a 
MDICanvas
2. Use the Flex profiler to monitor the memory
3. You will see that the windows are not garbage collected after they are 
closed (even when you trigger garbage collection using the profiler). The 
reason is that the MDIManagerEvents are cached to send an event when the 
corresponding Effect has finished and they keep a link to the involved 
window(s). These cached instances are removed from the collection when the 
effect sends the EffectEvent.EFFECT_END. However, for some effects there 
are no effect instances and as such the EffectEvent.EFFECT_END is never 
dispatched.
To "fix" this memory leak, the executeDefaultBehavior method should only 
add the mgrEvent to the cache after the effect has been started and there 
are instances created (see attached patch file).

What is the expected output? What do you see instead?
Expected output is that the windows are garbage collected some time after 
they have been closed. They are not.

What version of the product are you using? On what operating system?
Working on the latest version from the SVN repository (the event cache has 
been introduced in MDIManager.as rev. 512

Please provide any additional information below.

Original issue reported on code.google.com by bruno.ba...@gmail.com on 8 Jan 2009 at 9:01

Attachments:

GoogleCodeExporter commented 9 years ago
hmm, typo : the revision of MDIManager.as that introduced the event cached is 
rev 152

Original comment by bruno.ba...@gmail.com on 8 Jan 2009 at 9:06

GoogleCodeExporter commented 9 years ago

Original comment by dmcc...@gmail.com on 8 Jan 2009 at 6:15

GoogleCodeExporter commented 9 years ago
Our application also slow-down. When we open multiple mdi window for long time,
I checked on task manager and memory used by application keeps on increasing.

Did you get any solution for this? the solution explained above is not cleared 
to us.

Original comment by rajkr.ch...@gmail.com on 15 Jun 2009 at 11:28

GoogleCodeExporter commented 9 years ago
thanks, it was really helpful :)

Original comment by swi...@gmail.com on 24 Sep 2009 at 11:17

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thanks I was able to test your fix and it works partially now. If I start with 
say 5 
MDI windows and remove 1. then the I have 5 objects left in the memory (even 
after 
forcing the garbage collector in profiler). I would expect it to have 4 
objects. Then 
I tried deleting my other window and now i am left out with 4 objects. (where I 
would 
be expecting 3 objects).

Below is the change that I did in MDIManager.as 
                // add this event to collection for lookup in the 
effect handler
                //mgrEventCollection.addItem(mgrEvent);

                // listen for start and end of effect

mgrEvent.effect.addEventListener(EffectEvent.EFFECT_START, onMgrEffectEvent)

mgrEvent.effect.addEventListener(EffectEvent.EFFECT_END, onMgrEffectEvent);

                //mgrEvent.effect.play();

                var instances:Array =  mgrEvent.effect.play();
                if (instances && instances.length>0) {
                    mgrEventCollection.addItem(mgrEvent);
                }

Please let me know if I am missing anything here. 

Original comment by veenache...@gmail.com on 19 Oct 2009 at 7:14

GoogleCodeExporter commented 9 years ago
Hello, there's any working roundtrip to this bug?
Thanks!

Original comment by carlos.s...@gmail.com on 25 Nov 2010 at 6:31

GoogleCodeExporter commented 9 years ago
// Mi own solution
        private function onCloseEffectEnd(event:EffectEvent):void
        {
            var window : MDIWindow = event.effectInstance.target as MDIWindow; 
            remove(window);

// SOLUTION remove all cached effect events for the window on window close

            var cursor : IViewCursor = mgrEventCollection.createCursor();
            var dontMoveNext : Boolean = false;
            do {
                if (cursor.current) {
                    var mgrEvent:MDIManagerEvent = cursor.current as MDIManagerEvent;
                    if (mgrEvent.window === window) {
                        cursor.remove();
                        dontMoveNext = true;
                    } else {
                        dontMoveNext = false;
                    }
                } else {
                    dontMoveNext = false;
                }
            } while (dontMoveNext || cursor.moveNext());
        }

Original comment by carlos.s...@gmail.com on 25 Nov 2010 at 7:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I believe the issue is that in MDIEffectsDescriptorBase there are a bunch of 
different methods which will return Effect objects.  This class is abstract 
should never be instantiated according to the flex api. What will happen is the 
effects will never get cleaned up because they will never play correctly. I 
would recommend either not returning an effect, or returning a concrete effect 
in order for the play method to actually work properly. 

Original comment by mungl...@gmail.com on 27 Dec 2012 at 1:05