Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3595718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:53:21+00:00 2026-05-18T19:53:21+00:00

I put together a quick sample just to test out the garbage collection convenience

  • 0

I put together a quick sample just to test out the garbage collection convenience functions in casalib.

All seems to work well (i.e, objects are removed from the stage, listeners are stopped) however I am using Mr. Doob’s stats display and it looks like my memory usage isn’t going down after the destroy method is called?

Here is my document class:

package {
import flash.text.TextField;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
import net.hires.debug.Stats;
import org.casalib.display.CasaMovieClip;
import flash.events.MouseEvent;

public class GarbageCollectionExample extends CasaMovieClip {

    public var clean:MovieClip = new MovieClip();
    public var garbage:CasaMovieClip = new CasaMovieClip();

    public function GarbageCollectionExample() {
        addChild(new Stats());
        clean.buttonMode = true;
        clean.mouseChildren = false;
        clean.addEventListener(MouseEvent.CLICK, onClean, false, 0, true);
    }


    private function onClean(e:MouseEvent):void
    {
        garbage.destroy();
        garbage = null;
        clean.removeEventListener(MouseEvent.CLICK, onClean);
        removeChild(clean);
        clean = null;
    }
}
}

And here is my movieclip class:

package {
import flash.text.TextField;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
import net.hires.debug.Stats;
import org.casalib.display.CasaMovieClip;
import flash.events.MouseEvent;

public class Garbage extends CasaMovieClip {

    public var timer1Display:TextField = new TextField();
    public var timer2Display:TextField = new TextField();
    public var eventChangeDisplay:TextField = new TextField();
    public var clean:MovieClip = new MovieClip();

    private var timer1count:int = 0;
    private var timer2count:int = 0;
    private var eventChangeCounter:int = 0;

    private var firstTimer:Timer;
    private var secondTimer:Timer;

    public function Garbage() {
        startEvents();
        addEventListener(Event.CHANGE, onEventChange, false, 0, true);
    }

    private function startEvents():void
    {
        firstTimer = new Timer(1000);
        firstTimer.addEventListener(TimerEvent.TIMER, onFirstTimer, false, 0, true);
        firstTimer.start();

        secondTimer = new Timer(200);
        secondTimer.addEventListener(TimerEvent.TIMER, onSecondTimer, false, 0, true);
        secondTimer.start();
    }

    private function onFirstTimer(e:TimerEvent):void
    {
        timer1Display.text = "first timer has played " + timer1count;
        timer1count++;
        dispatchEvent(new Event(Event.CHANGE));
    }

    private function onSecondTimer(e:TimerEvent):void
    {
        timer2Display.text = "second timer has played " + timer2count;
        timer2count++;
        dispatchEvent(new Event(Event.CHANGE));
    }

    private function onEventChange(e:Event):void
    {
        eventChangeDisplay.text = "event has changed " + eventChangeCounter + " times";
        eventChangeCounter++;
    }

    override public function destroy():void
    {
        firstTimer.stop();
        secondTimer.stop();
        removeEventListeners();
        super.destroy();
    }

}
}

Are my items actually being marked for garbage collection? What am I doing incorrectly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T19:53:22+00:00Added an answer on May 18, 2026 at 7:53 pm

    I decided to remove everything from the stage and all my event listeners (basically, an empty flash movie) and to just addChild(new Stats());

    This alone takes up 34KB of memory and gradually increases, so I guess this accounts for my memory “creeping up” after I remove and destroy everything else…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I put together a quick sample just to test out the garbage collection convenience
I've put together a quick test using the DotNetZip library which opens a zip
I put together a sample scenario of my issue and I hope its enough
I put together a quick WinForm/embedded IE browser control which logs into our company's
I thought I'd put together a quick script to consolidate the CSS rules I
Have a quick project I need to put together for windows that can have
I'm looking to put together a simple scriptable backup utility to grab all the
I have just started learning and have put together the form below. The confusion
I put together a class yesterday to do some useful task. I started alpha
As I put together each asp.net page It's clear that most of the time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.