4 Replies Latest reply on Mar 13, 2008 3:24 AM by Starlover_jacob

    Popup Dialogs don't free memory when closed

      The Popup Manager consumes huge amounts of memory and never gives it back.

      When I create a trivial custom popup dialog, show it and then close it there is no noticeable problem.
      But if my popup dialog has any containers, components and webservices in it, the memory is never ever freed.
      If your end user triggers the same popup a few times, it's easy to see the memory consumption spiral till the browser crashes.

      Any ideas? I've already read Alex's blog (which is really useful for UI stuff but not this issue) and his powerpoint on the GC.

      We do have two (highly unprofessional workarounds) which avoid the PopupManager altogether:
      1) Use browser popup dialogs
      2) Simply plonk all the components into a titlewindow and make it visible/invisible so at least you limit the damage to one instance.

      PS: Alex (and the rest of the Adobe Engineers) - you guys should really try to use Flex Builder every now and then rather than ActionScripting your way through everything with vi or notepad.
        • 1. Re: Popup Dialogs don't free memory when closed
          You could try changing the scope of the component being popped up. For example, if you are using a TitleWindow you could make the TitleWindow a property of your Application. That way there is only one TitleWindow instance and the PopUpManager is just adding it and removing it from the Display List (as well as doing the other PopUpManger stuff). In a lot of the popup examples I have seen, the TitleWindow is creates as a variable within a function and so a new instance is created each time the function is called. Not really an issue with most non-visual variables as they are destroyed when the function is complete but with some visual components if there are strong references to the component (event listeners, registered with StyleManager, etc), that component may never be completely destroyed. I haven't tested this theory but it may be worth trying.
          • 2. Popup Dialogs don't free memory when closed
            BigChug Level 1
            Thanks dazweeja , that workaround works too. It limits the damage to one instance in memory.
            I agree with your diagnosis.

            Variables declared within a function that are explicitly set to null would ideally be 'fully' marked for the Garbage collector somehow once the function is out of scope. (By 'fully', I mean that all children of that object should also be destroyed). PopupDialogs don't do that.

            Personally, using global variables is fine by me but it's not a very aesthetically appealing solution for some.
            • 3. Re: Popup Dialogs don't free memory when closed
              Starlover_jacob Level 1
              Hey guys,
              Do you have a code example for me please?
              I am using the popup for a piece of code that takes some time to run.. and when its done running i remove the popup. But when i run the script again, my popup doesn't appear. :(

              Here the code i use:

              private var pop2:Canvaspopup;
              public function imageSelected(event:Event):void // i cum here on the select event from a file dialog box.
              pop2=new Canvaspopup();
              pop2 = Canvaspopup(PopUpManager.createPopUp(Application.application as Sprite,Canvaspopup,true));
              // here i do some image stuff like use a loader for the selected image
              public function handleImageComplete(event:Event):void //when the loader is complete i cum here
              // do some image resizing and saving

              • 4. Re: Popup Dialogs don't free memory when closed
                Starlover_jacob Level 1
                hey guys,

                sorry for my question.

                in the imagecomplete handler i set pop2 = null
                in the image select handler my if is always false so it never makes another popUp

                my mistake