Monday, August 22, 2011

Memory Leaks And Other Garbage Collection Adventures in the AVM

I've gathered some info online about flash's garbage collector and am getting ready to dive head-first into this fun and exciting world of trying to fix the various memory leaks in Cardinal Quest.

Funny, I've been coding in java for a decade and c#/python/other GC-languages for years and never had major issues with memory leaks. But the AVM's garbage collector is apparently a different beast altogether.

It seems I might have to manually release memory by assigning null to variables I don't need anymore. It's like coding in c again! :)

Wish me luck, and if you have any tips don't hesitate to mention them!



  1. Python's popular implementation, aka CPython, is not garbage collected.

  2. It isn't? Never had to worry about memory leaks in python tho!

    Maybe because I never done anything large with it,


    "The portable garbage collection has been included in Python since version 2.0. It is enabled by default. Be happy."

  4. I had a hunch that you had a few memory leaks... the advantage of playing on an old laptop is it gets obvious fast.

  5. I wish you luck! Some thoughts:

    - Don't forget to remove event listeners or don't add them using a weak reference (

    - You probably don't use any ExternalInterface calls in your game, but if you do there might be a risk that the entire app doesn't get cleaned up by the browser and linger in the DOM if the user reloads the page (I've seen this happen when certain combinations of browser plugins are installed)

    - Don't forget the optional weakKeys in the c'tor of Dictionary

    - Use the profiler and check object creation and analyze the memory usage of your app

    - Not sure if you're creating and throwing away a lot of BitmapData, but if you do you might want to call BitmapData.dispose()


  6. Björn: thanks for the tips! I suspect you meant I *should* use a weak ref rather than *not use* it?

    Also, I suspect the problem is indeed with BitmapData's, still working on tracking it down.