Jump to content


BlitMask delete cache

Moderator Tag

Recommended Posts

I am using copyPixels() to copy data from 12 large 3000x3600 bitmapData instances already loaded into memory. The data is being copied into a Bitmap which is the target for my BlitMask.


I've tried all sorts of permutations of using bitmapData.dispose() but whatever I do everytime I use copyPixels on one of the instantiated images it adds about another 40Mb to my BlitMask (probably the size of the 8bit 3000x3600pixel image in cache)


I try and force the garbage collection using System.pauseForGCIfCollectionImminent(0.01); but I only seem to increase the amount of memory being allocated.


It is only when I dispose of the BlitMask that I can free up memory.


Any ideas or should I try another approach? I have the feeling that because BlitMask caches the display object as a bitmapData object that it is also drawing in the cache created by the copyPixels() function.


I am trying to make a music score scroller so I cannot interrupt the display of the image whilst the music is playing.


Many Thanks



Link to comment
Share on other sites

If I understood your description properly, it sounds like normal behavior. When you copyPixels(), Flash has to store some stuff in memory to execute that call. I can't think of anything inside BlitMask that would improperly block gc or anything.


Maybe instead of copyPixels() you could just drop things into your Sprite that's the target of the BlitMask and then have it update(null, true) to force the redraw. Of course that'll still require some memory to do, but as long as you're also removing old/invisible stuff from the Sprite whenever you're adding the new stuff, it should balance out after gc. Just a thought.

Link to comment
Share on other sites

  • 2 weeks later...

Just tried adding Bitmap display objects with unique references, removing them from the BlitMask target Sprite as they are no longer required, disposing of the bitmapData and setting the references to null.


I am then disposing of the old Bimaps with:



myBitmap = null;


and calling:



after I have updated the BlitMask:



The memory keeps going up with each new Bitmap added.


Any help would be much appreciated.

Link to comment
Share on other sites

I'm not quite sure what to say other than it's normal for memory to increase when you add Bitmaps. It's very difficult to troubleshoot blind, but I'm not aware of any gc issues with BlitMask at all. 

Link to comment
Share on other sites

So if I am adding Bitmaps to the Sprite (which is the target of the BlitMask) then removing them, calling dispose() and setting them to null these should be picked up by the gc?


Are you sure BlitMask is not retaining references to these added and then removed Bitmaps?

Link to comment
Share on other sites

I think that's exactly what he's saying. BlitMask never even refers specifically to, let alone saves, any of the Bitmap children of the target DisplayObject (your Sprite). It just BitMapData.draw()s the target into its own BitmapData.


If you are surely disposing of your Bitmaps then I can't see any reason BlitMask could prevent their eventual garbage collection. Are you certain that the memory is never being released, ever? i.e. are you getting Flash to increase memory usage to a point that it crashes because of insufficient memory?


What are you using to monitor memory usage by the way?

Link to comment
Share on other sites

Thanks for your answers.


I am using Monster DeBugger for memory usage. Memory gets released when I set the BlitMask to null and call it's dispose() function.


It's not crashing Flash I have got plenty of memory on my desktop. It just keeps on increasing the memory until it reaches about 650Mb once all the images have been used. It's almost like they are being cached.


I am using the bitmpaData.copyPixels() to create the Bitmaps, but I am calling dispose() and setting them to null.

Link to comment
Share on other sites

I have found the culprit.


it is BitmapData.copyPixels();


I am using BitmapData.draw() now.


I am getting a more respectable 250Mb constant memory useage, as I would expect.


I can only assume that copyPixels is caching the data with the expectation that it may be required and is obviously referencing where the data is being used, so only when the BlitMask is destroyed am I getting the memory back.


I expect copyPixels is more appropriate where the graphics are going to be repeatedly re-used. I used this method because the adobe docs suggested it would be faster.


Your help is much appreciated in eliminating the possibilities.


Have a look here for an excellent tutorial on how BitmapData.draw() works:


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.