A Flash Developer Resource Site

Results 1 to 20 of 51

Thread: AS3 is FAST! Redux - CopyPixels vs. Sprite Pooling

Hybrid View

  1. #1
    Member
    Join Date
    Jan 2004
    Location
    Copenhagen, Denmark
    Posts
    50
    It's extremely easy to spike the memory. In my first try at it I went from 0 to 500MB in seconds. All it takes is to allocate a new BitmapData of a reasonably large size (800x600) on each EnterFrame. Sure, the old ones will be deallocated - eventually. So in the best case you will see spiking before the garbage collector kicks in a frees the memory of the old BitmapData - but if you're going too fast (30FPS @ 800x600) you can easily hit virtual memory before the garbage collector gets a chance to run. And lets just say that when that happens things (and especially FPS) go down hill fast.

    The solution is of course to "pool" your BitmapData by reusing them in each frame. Either completely copying them over with new data, or if it's for a canvas type thing, simply clear them with a fillRect.

    ------------------------

    Ahr, hadn't actually seen there was a dispose method on the BitmapData. Don't know how that would work, but there shouldn't be too much difference between reallocating and doing fillRect on an existing BitmapData. Would need to speedtest it though to see if that's true ...

    And just tested dispose. You're absolutely right - no memory spikes at all. Thanks
    Last edited by YaiEf; 05-24-2007 at 08:02 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center