15 Replies Latest reply on Oct 22, 2007 11:19 PM by skalamichal

    Problem with removeMovieClip

    skalamichal
      Hello,

      I have trouble with attaching and removing of MovieClips. I have many image movieclips in library and I need to display them in sequence. The simplest way is to attach them on frame to display them, each image clip on separate frame. But without removing them the memory usage is too high and the flash player displays later only red rectangle.

      I've tried to remove the last attached movieclip, when the second is displayed, but it's not removed from memory.

      Example code:
      Frame 1
      attachMovie("image_1", "clipname", 100);
      Frame 2
      clipname.removeMovieClip();
      attachMovie("image_2", "clipname", 101);
      Frame 3
      clipname.removeMovieClip();
      attachMovie("image_3", "clipname", 102);

      Frame x
      clipname.removeMovieClip();
      attachMovie("image_x", "clipname", 100 + x);
      stop();

      I've tried to remove the clip with the removeMovieClip(clipname) function too.

      What I'm doiing wrong. I really need to clean the memory. Shouldn't be the memory cleaned by the GC?

      Thanks for quick response,
      Michal
        • 1. Re: Problem with removeMovieClip
          kglad Adobe Community Professional & MVP
          what makes you think your movieclips are not being removed?

          p.s. a simpler way to remove them is to use the same depth when you attach them.
          • 2. Re: Problem with removeMovieClip
            skalamichal Level 1
            Because I have a really big Flash project with 400+ image clips. I attach each image on one frame and remove the clip before. And the memory usage goes over 1.8 GB. Also, when I use removeMovieClip function to remove the clip attached before, I hoped the memory would be cleaned. I tried to set the newName (movieclip instance name) variable to null after the removeMovieClip function, but even this hasn't helped.
            • 3. Re: Problem with removeMovieClip
              skalamichal Level 1
              Also, I've tested the way to attach all the image clips to the same depth. This was the first thing I've done. But in this case the memory wasn't cleared as in the other cases.

              Michal
              • 4. Re: Problem with removeMovieClip
                kglad Adobe Community Professional & MVP
                what do you mean by memory usage? what are you using to measure memory usage?
                • 5. Problem with removeMovieClip
                  clbeech Level 3
                  well, once you advance to the next frame (assuming that they are keyframed) the previous instance is no longer instatiated, and therefore can't be reached by the code to get removed. And what are you 'attaching' the clip to? 'this'? (or the main timeline)

                  This seems like a gallery or book, where you advance through the images 'page by page' is this right? If so I would definitely do as kg suggests and load to the same level, in fact you could loop this, increment with variables and never need to leave the first frame. This would really decrease the memory needs, because you won't have all those frames. Additionally, you could use the MovieClipLoader class and load the next image from an external source, further decreasing the memory load, due to 'on board' assets.

                  However, one remedy might be to run the removeMovieClip() statement previous to leaving the frame, from the button instance that advances the playhead.

                  EDIT: dang it!!! sorry again kg :)
                  • 6. Re: Problem with removeMovieClip
                    kglad Adobe Community Professional & MVP
                    if the code's as he presented it, the attachment is to the timeline that contains the code. and that will exist in the next keyframe.
                    • 7. Re: Problem with removeMovieClip
                      clbeech Level 3
                      Doh! yep, for sure, for some reason I was thinking of an instance attachment, hello! lol!
                      • 8. Re: Problem with removeMovieClip
                        skalamichal Level 1
                        It's very simple to check the memory usage of the Flash Player in Process Explorer. I can easy check that the memory usage grows until 1.8 GB. Then any next image isn't attached, only red rectangle is shown. I'd like to give you a link to see the example, but the flash movie is really too large.

                        Michal
                        • 9. Re: Problem with removeMovieClip
                          skalamichal Level 1
                          It's very simple to check the memory usage of the Flash Player in Process Explorer. I can easy check that the memory usage grows until 1.8 GB. Then any next image isn't attached, only red rectangle is shown. I'd like to give you a link to see the example, but the flash movie is really too large.

                          Michal
                          • 10. Re: Problem with removeMovieClip
                            skalamichal Level 1
                            It's very simple to check the memory usage of the Flash Player in Process Explorer. I can easy check that the memory usage grows until 1.8 GB. Then any next image isn't attached, only red rectangle is shown. I'd like to give you a link to see the example, but the flash movie is really too large.

                            Michal
                            • 11. Re: Problem with removeMovieClip
                              skalamichal Level 1
                              Nice, one post 2 times posted. And the service should be unavailable. Sorry for this.
                              • 12. Re: Problem with removeMovieClip
                                skalamichal Level 1
                                Hello,

                                I've issues with running another flash, and this is only example that I've used in the flash and I was able to reproduce the issue.

                                In this example it is really a flash application, which you can imagine as slide show. I would like to prevent the memory usage of this flash app. I know, that I can anytime load external images, but this is the case where I can't do this this way. And I can't have the attach code on one frame in for example onEnterFrame function. I need to have each image on separate frame. I assumed that when I attach an movieclip from library in depth for example 10, that another attachment to the same depth will remove the before used movieclip from memory, but it seems, that the clip isn't removed. I've also tried removeMovieClip method, NULL assignment to the movieclip instance variable, unloadMovie ... Nothing has worked.

                                I know, that when a reference count is 0, then object (movieclip) can be removed from memory by the GC.

                                I don't know, what can be the issue. I've got an idea, if there isn't some issue with BitmapData, because I attach movieclips with PNG images. Any image is decompressed and that's why the memory usage grows, I guess. And maybe the decompressed image isn't removed? I don't know, any thoughts?

                                Thank you,
                                Michal
                                • 13. Re: Problem with removeMovieClip
                                  skalamichal Level 1
                                  Just an idea, can it be that the flash movie is just too huge? That 600MB SWF movie is too big for the Flash Player?

                                  Michal
                                  • 14. Re: Problem with removeMovieClip
                                    clbeech Level 3
                                    yeah, that's huge!! It would take half an hour for the average use to load, if they didn't run into any errors.

                                    If this is just a straight running animation sequence or something you could maybe export it as a FLV movie and then stream it into a player. if it's a slide show that needs interactive control, you might be able to manage this using que points.

                                    What size images are you using here, resolution (dpi)? have they been optimized? (all images should be at 72dpi, screen res, also jpg files may compress better saving storage size)

                                    Why exactly is it that you can't load these files externally?
                                    • 15. Re: Problem with removeMovieClip
                                      skalamichal Level 1
                                      Yes, it's huge, but as I've written above, this is only a example flash, where the issue is very soon visible. Original flash application I'm using is a little bit above 80MB, which is too not very small flash movie, but it goes to the same error. When I've tracked the issue, it's related to the memory usage. Any of this SWF movies fails, when it reaches the 1.8GB memory.

                                      From my point of view, the issue is caused, when the flash movie decompresses the image to display it. When the image should be displayed, it must be decompressed from JPEG or PNG image. And when in the movie are many images (400 example) and the memory isn't freed, the SWF takes the full memory available and then fails. And also I can then see only red rectangle on the Stage.

                                      I really don't understand, why the memory isn't cleared, when I use removeMovieClip ... and other ways to remove the movieclip (image) instance from memory. I guess, I must doing something wrong or is there some issue in GC?

                                      In the example is this only a animation sequence, but not in the real application. I can't use FLV. The image size could be different, this is possible to set up by the user. All images are optimized according to user settings. It's possible to use Lossless images or JPEG images in more quality settings. But I can't tell any of my customers to reduce the image quality if they don't want :(

                                      And why not externally ... just because of play speed.

                                      Michal