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

  • SEARCH
  • Home
  • 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 8345359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:39:03+00:00 2026-06-09T06:39:03+00:00

This is simple test on AS3 for BitmapData memory allocation. private function memoryTest(): void

  • 0

This is simple test on AS3 for BitmapData memory allocation.

private function memoryTest(): void
{
  trace("BitmapData memory test. Create bmps..."); // First breakpoint
  var bmps:Array = new Array (1000);

  for (var i:int=0; i<1000; i++)
  {
    bmps[i] = new BitmapData(451, 451, true, 0);
    trace(i+". bmp created");
  }

  trace("All bmps created."); // Second breakpoint

  for (i=0; i<1000; i++)
  {
    bmps[i].dispose();
    bmps[i] = null;
  }
  bmps.splice(0, bmps.length);
  bmps = null;

  freeMemoryGC();

  trace("All bmps deleted.");
  trace("Test complete."); // Last breakpoint
}

private function freeMemoryGC(): void
{
  // the GC will perform a full mark/sweep on the second call.
  try
  {
    new LocalConnection().connect('foo');
    new LocalConnection().connect('foo');
  }
  catch (e:*)
  {
  }

  System.gc();
  System.gc();
}

There are 3 breakpoints in this test, that are commented in code. Breakpoints pause program during some time. Breakpoints correspond to the horizontal lines on this memory state chart.

memory usage graph

My question is: why not all memory was free after dispose() calls? What wrong in this code and how to clear BitmapData objects properly?

UPDATE 1:
I don’t think that problem is in garbage collector. dispose() works out of GC and it should release the pixels data. Also this example should allocate 451*451*4*1000 bytes theoretically. But this test application allocates 25% more bytes in System.privateMemory and these 25% is never released by GC and dispose().

UPDATE 2:
If I create 13 images 4059×4059 px instead of 100 images 451×451 px, then memory allocates exactly equals to theoretical size and memory is released properly after call GC! I don’t know why it happens.

UPDATE3:
Here is my results of interval test, created by Daniel MesSer in him answer:
memory usage graph on interval test

  • 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-06-09T06:39:04+00:00Added an answer on June 9, 2026 at 6:39 am

    Try and remove the thing about local connection in free memorygc-function. Does that solve it?

    EDIT:

    package nyx_gaming_group.as3_tests {
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.system.System;
    import messer_entertainment.MesSerUtils;
    
    /**
     * ...
     * @author Daniel Dahlkvist
     */
    public class BitmapDataMemoryLeak extends Sprite {
        private var _bitmaps:Array;
    
        public function BitmapDataMemoryLeak() {
            run();
        }
    
        private function run():void {
            MesSerUtils.delayCall(createBitmaps, 150);
            MesSerUtils.delayCall(destroyBitmaps, 4500);
            MesSerUtils.delayCall(freeMemoryGC, 4700);
            MesSerUtils.delayCall(run, 8000);
        }
    
        private function createBitmaps():void {
            trace("BitmapData memory test. Create bmps..."); // First breakpoint
            _bitmaps = new Array(1000);
    
            for (var i:int = 0; i < 1000; i++) {
                _bitmaps[i] = new BitmapData(451, 451, true, 0);
            }
    
            trace("All bmps created."); // Second breakpoint            
        }
    
        private function destroyBitmaps():void {
            for (var i:int = 0; i < _bitmaps.length; i++) {
                _bitmaps[i].dispose();
                _bitmaps[i] = null;
            }
            _bitmaps = null;
    
            trace("All bmps deleted.");
            trace("Test complete."); // Last breakpoint
        }
    
        private function freeMemoryGC():void {
            System.gc();
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried this as a simple test: @functions { private MvcHtmlString helloWorld() { return
I have this simple test project just to test the IncludeExceptionDetailInFaults behavior. public class
We have a ubuntu test server that this simple script works fine on where
Here's the simple test to reproduce the issue, this is the single class in
im using a simple test script from http://www.tuxradar.com/practicalphp/8/11/0 like this <?php $fp = fopen(foo.txt,
This is for Play! Framework 2.0. I'm trying to write a simple test case
This is a simple script I have written to test command line argument handling:
This question is fairly fundamental.I gave a simple and straighfoward test on my cygwin:
My simple requirement: Reading a huge (> a million) line test file (For this
I created a simple application inspired by this example in order to test all

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.