Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Garbage collection?

Community Beginner ,
Nov 11, 2009 Nov 11, 2009

Hello!

I have made a xml slide show where the pictures move on and off of the stage when the user clicks next. But after so many pictures it freezes up. From my understanding something like garbage collection needs to happen but I guess the data contained in the slideshow, such as the pictures that are no longer on the screen, are not seen as "garbage collectable".

I am not sure what code to post to better help someone understand - I have 145 lines of code - but I am attaching the code here if someone is generous to look at it! I have attached a CS4 AS3 document and a text doc if you are not able to read that one.

Would you be able to help me with this? Even if you could tell me what to look at to figure it out that would be nice!

Tks! O

TOPICS
ActionScript
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 12, 2009 Nov 12, 2009

here's one way to do what i just described:

oluc wrote:

Tks! Now what if all of the pictures are loaded through one movieclip? Here is excerpts of the code I have:

var rawImage:String;

var imgData:XML;

var lastImageIndex:int = 0;

var imageLoader:Loader;

var imgNum:int;

var imageLoaderHost: MovieClip;

public function packagedF(e:Event = null):void {

     rawImage = imgData.image[imgNum].imgURL;

     lastImageIndex = imgData.*.length() - 1;

     rawW = imgData.image[imgNum].imgW;

     rawH = imgData.image[

...
Translate
Community Expert ,
Nov 11, 2009 Nov 11, 2009

you need to remove all references to objects you want gc'd, you need to remove all listeners attached to those objects, remove the objects from the displaylist, stop all streams (which doesn't apply to a bitmap display) and finally assign the object to null.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 12, 2009 Nov 12, 2009

Tks! Now what if all of the pictures are loaded through one movieclip? Here is excerpts of the code I have:

var rawImage:String;

var imgData:XML;

var lastImageIndex:int = 0;

var imageLoader:Loader;

var imgNum:int;

var imageLoaderHost: MovieClip;

public function packagedF(e:Event = null):void {

     rawImage = imgData.image[imgNum].imgURL;

     lastImageIndex = imgData.*.length() - 1;

     rawW = imgData.image[imgNum].imgW;

     rawH = imgData.image[imgNum].imgH;

     master_mc = new MovieClip;

     master_mc.x = 0;

     master_mc.y = 166.4;

     addChild(master_mc);

     imageLoaderHost = new MovieClip  ;

     imageLoader = new Loader  ;

     imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);

    imageLoader.load(new URLRequest(rawImage));

     master_mc.addChild(imageLoaderHost);

     imageLoaderHost.addChild(imageLoader);

     imageLoaderHost.y = (stage.stageHeight - Number(rawH)) /5;

    imageLoaderHost.x = 1780;

     TweenMax.to(imageLoaderHost, 1.5, {x:(stage.stageWidth - Number(rawW)) /1.59, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut});

     TweenMax.from(imageLoader, 1.5,  {blurFilter:{blurX:100}});

    imageLoader.scaleX = .75;

    imageLoader.scaleY = .75;

     clearInterval(imgNum);

     clearInterval(lastImageIndex);

}

public function loadCompleteHandler(event:Event) {

     imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadCompleteHandler);

     imageReflect = new Reflect({mc:imageLoaderHost,alpha:50,ratio:50,distance:1,updateTime:2,reflectionDropoff:2});

}

public function nextImgF(e:MouseEvent):void {

     // Button glows on and off:

     TweenMax.from(btnNext, .5, {glowFilter: {color:0x0098ff, alpha: 0.6, blurX:45, blurY:45, strength:10, quality:3}, ease:Quad.easeInOut});

     //Moves image currently on screen forward to bring on next picture:

     TweenMax.to(imageLoaderHost, 2, {blurFilter: {blurX:100}, x:-1500, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut});

     imgNum = imgNum < lastImageIndex ? imgNum + 1:0;

     // Refers to function to bring on next picture

     packagedF();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 12, 2009 Nov 12, 2009

my post was not contingent on anything including how you load your bitmaps.

but, to clarify, you load using a loader.  in your case, imageLoader.   to what timeline you add imageLoader is irrelevant for this discussion, as far as i can see.

i can see that you're removing a listener that's applied to your loader's contentLoaderInfo property.  but you're not nulling your loader so it's not ready for gc.  i'm not sure you removed it from its parent, either which would also prevent it from being gc'd.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 12, 2009 Nov 12, 2009

Okay I see. So I guess my question really is: How do I remove my pictures from the display list if they are all loaded from one loader in one movieclip? In looking at my code I don't see a way to remove the pics without removing the whole thing that makes the pictures display - which would mean that slideshow would not work any more. Or, how do I null the loader without making the whole gallery not work any more?

The user has to have the capability to go back to any image that he saw previously. So if I remove an image, I would have to make it so the user could still ref an earlier pic.

Does that make sense or am I off?

Or, is there a way to transfer the pictures to another mc and make that "GCable" as the pictures go into it - or something like that?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 12, 2009 Nov 12, 2009

every time you call packagedF(), you create a new loader.  they all have the same reference name so that may be confusing but, you are creating one new loader each time packagedF() is called.  if you only call packagedF() once each time your swf is displayed, then you are creating one loader.

to ready that loader for gc, you need to remove it from its parent and then null it (in addition, to removing that listener which you've already done):

imageLoader.parent.removeChild(imageLoader);  // these 2 line should only be executed just prior to creating a new loader or, when you no longer need to display the loaded bitmap.

imageLoader=null;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 12, 2009 Nov 12, 2009

here's one way to do what i just described:

oluc wrote:

Tks! Now what if all of the pictures are loaded through one movieclip? Here is excerpts of the code I have:

var rawImage:String;

var imgData:XML;

var lastImageIndex:int = 0;

var imageLoader:Loader;

var imgNum:int;

var imageLoaderHost: MovieClip;

public function packagedF(e:Event = null):void {

     rawImage = imgData.image[imgNum].imgURL;

     lastImageIndex = imgData.*.length() - 1;

     rawW = imgData.image[imgNum].imgW;

     rawH = imgData.image[imgNum].imgH;

     master_mc = new MovieClip;

     master_mc.x = 0;

     master_mc.y = 166.4;

     addChild(master_mc);

     imageLoaderHost = new MovieClip  ;

if(imageLoader!=null){

imageLoader.parent.removeChild(imageLoader);

imageLoader=null;

}

     imageLoader = new Loader  ;

     imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);

    imageLoader.load(new URLRequest(rawImage));

     master_mc.addChild(imageLoaderHost);

     imageLoaderHost.addChild(imageLoader);

     imageLoaderHost.y = (stage.stageHeight - Number(rawH)) /5;

    imageLoaderHost.x = 1780;

     TweenMax.to(imageLoaderHost, 1.5, {x:(stage.stageWidth - Number(rawW)) /1.59, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut});

     TweenMax.from(imageLoader, 1.5,  {blurFilter:{blurX:100}});

    imageLoader.scaleX = .75;

    imageLoader.scaleY = .75;

     clearInterval(imgNum);

     clearInterval(lastImageIndex);

}

public function loadCompleteHandler(event:Event) {

     imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadCompleteHandler);

     imageReflect = new Reflect({mc:imageLoaderHost,alpha:50,ratio:50,distance:1,updateTime:2,reflectio nDropoff:2});

}

public function nextImgF(e:MouseEvent):void {

     // Button glows on and off:

     TweenMax.from(btnNext, .5, {glowFilter: {color:0x0098ff, alpha: 0.6, blurX:45, blurY:45, strength:10, quality:3}, ease:Quad.easeInOut});

     //Moves image currently on screen forward to bring on next picture:

     TweenMax.to(imageLoaderHost, 2, {blurFilter: {blurX:100}, x:-1500, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut});

     imgNum = imgNum < lastImageIndex ? imgNum + 1:0;

     // Refers to function to bring on next picture

     packagedF();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 13, 2009 Nov 13, 2009

kglad, thank YOU very much! That definitely removes it.

If I wanted to remove it after it goes off stage shouldn't I be able to do this:

if (imageLoader.x == -1500 && imageLoader!=null) {

    imageLoader.parent.removeChild(imageLoader);

    imageLoader=null;

}

I tried it but with the x position at 50 and it did not remove. Do you know what I am missing/doing wrong?

TIA

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 13, 2009 Nov 13, 2009

Or what about this!? I tried this after lots of other trial and error and it moves it off the stage but I am not sure if it is removing the pic..

if ( imageLoader!=null && imageLoader.parent.x < 60) {

    imageLoader.parent.removeChild(imageLoader);

    imageLoader=null;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 13, 2009 Nov 13, 2009

if you want to remove the loader after it moves to a certain position, you have the repeatedly check if the loader's at that position.  but if you create another loader with the same name before removing and nulling your previous loader, you'll have problems.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 13, 2009 Nov 13, 2009

Oh, I see. So I would have to rewrite all of the code to do something like - put the nulling in a loop and somehow make the name different for each new loader created and make that recognizable by the nulling loop too?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 14, 2009 Nov 14, 2009

i don't know that you need to rewrite any significant part of your code but, you'll need to rewrite some.  if you want to remove a loader after one of your tweens complete, there's probably an onComplete property of your tween you can use.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 15, 2009 Nov 15, 2009

I tried onComplete and then removing the loader and I also tried onComplete then function which lead to a constructor that removed. The only thing is that the next picture starts comming on the stage before the previous one is fully off and so when I do that it waits till the image is all the way off the screen and then loads the next image but there are a couple of seconds with blank screen which I am trying to avoid. Otherwise that would have worked beautifully.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 18, 2009 Nov 18, 2009

Any other ideas?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2009 Nov 18, 2009

what are you trying to do?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 18, 2009 Nov 18, 2009

I have a gallery - right now, after going through about 80 pictures when the flash is exported, the flash starts to chug and freeze up. I have over 200 pictures in the gallery but I cant get past 80! I am trying to make it so that when a picture goes off of the stage to the left, it is gotten rid of so that the computer does not have useless computation of the picture that is not on the screen. The only thing is that I have all of the pictures loading through one loader and one starts to come on the stage as the other goes off (so they are both on the stage at the same time for a little bit). So, I am not able to remove the loader without getting rid of the picture that is comming on the stage. Does that make sense? If not pls let me know and I can explain differently.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2009 Nov 18, 2009

:


var rawImage:String;

var imgData:XML;

var lastImageIndex:int = 0;

var imageLoader:Loader;

var imgNum:int;

var imageLoaderHost: MovieClip;

public function packagedF(e:Event = null):void {

     rawImage = imgData.image[imgNum].imgURL;

     lastImageIndex = imgData.*.length() - 1;

     rawW = imgData.image[imgNum].imgW;

     rawH = imgData.image[imgNum].imgH;

     master_mc = new MovieClip;

     master_mc.x = 0;

     master_mc.y = 166.4;

     addChild(master_mc);

     imageLoaderHost = new MovieClip  ;


     imageLoaderHost.imageLoader = new Loader() ;

     imageLoaderHost.imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);

    imageLoader.load(new URLRequest(rawImage));

     master_mc.addChild(imageLoaderHost);

     imageLoaderHost.addChild(imageLoader);

     imageLoaderHost.y = (stage.stageHeight - Number(rawH)) /5;

    imageLoaderHost.x = 1780;

     TweenMax.to(imageLoaderHost, 1.5, {x:(stage.stageWidth - Number(rawW)) /1.59, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut});

     TweenMax.from(imageLoader, 1.5,  {blurFilter:{blurX:100}});

    imageLoader.scaleX = .75;

    imageLoader.scaleY = .75;

     clearInterval(imgNum);

     clearInterval(lastImageIndex);

}

public function loadCompleteHandler(event:Event) {

     imageLoaderHost.imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadCompleteHandler);

     imageReflect = new Reflect({mc:imageLoaderHost,alpha:50,ratio:50,distance:1,updateTime:2,reflectio nDropoff:2});

}

public function nextImgF(e:MouseEvent):void {

     // Button glows on and off:

     TweenMax.from(btnNext, .5, {glowFilter: {color:0x0098ff, alpha: 0.6, blurX:45, blurY:45, strength:10, quality:3}, ease:Quad.easeInOut});     //Moves image currently on screen forward to bring on next picture:

// using an onCompleteParams is important

     TweenMax.to(imageLoaderHost, 2, {blurFilter: {blurX:100}, x:-1500, y:(stage.stageHeight - Number(rawH)) /5, ease:Quad.easeInOut,onComplete:removeF,onCompleteParams:[imageLoaderHost]});

     imgNum = imgNum < lastImageIndex ? imgNum + 1:0;

     // Refers to function to bring on next picture

     packagedF();

}

function removeF(mc:MovieClip){

mc.parent.removeChild(mc);

mc=null;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 21, 2009 Nov 21, 2009
LATEST

Hey, Thanks a ton! I used the onComplete and onCompleteParams. I have a question on the onCompleteParams: What does it mean "An Array of parameters to pass the onComplete function"? I think I specifically do not understand the term "pass".

Maybe I will understand this next question after I understand the above but...

Would you mind explaining the mc.parent.removeChild(mc)? From what get, with onCompleteParams tells the onComplete that it is dealing with the imageLoaderHost so when the removeF function gets executed thats what it's dealing with - the imageLoaderHost. Now, the imageLoaderHost is an mc, so does the mc in mc.parent..... link to the imageLoaderHost? and if so, how does it recognize to do that?

I have one more question after this but I'll save it.

Thanks in advance!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines