Controlling cache



Cache is an as3 class, which is made for memory monitoring and forced cleaning. You can define the memory usage limit, the delay and that’s it – the Cache class will clear memory every time memory usage exceeds your limit.

Download source files


import com.chargedweb.system.Cache;

Cache.getInstance().debug = true;
Cache.getInstance().sizeLimit = 10;
Cache.getInstance().checkDelay = 500;

2 Comments (+add yours?)

  1. Mamzelle
    Apr 06, 2010 @ 08:11:09

    Hi, I tried you class but it does not seem to work in Flash IDE:

    Cache.clear() called :: memory usage exceeded ::
    memory usage: 11.33mb
    memory limit: 10mb
    memory usage [after clean()]: 11.33mb

    Do you know why ?

  2. jloa
    Apr 06, 2010 @ 15:36:29

    Yeah, the class just says that the memory limit exceeded and it forced the gc (garbage collector) to try to clean up the memory.
    So, if you are actually using 11.33 mb of RAM there will be no memory cleaning.
    The idea with this class was that when you create e.g. 20 animations on your display list, which would take you 50 mb of your ram, and after you remove them from the display list (i.e. delete them), flash player will not release the memory immediately, as it takes time for the gc to “notice” the deletion. That’s when this class come up to. You set up a limit for the average objects number (say, usually it takes 25 mb for 10 objects), and the Cache class will force the gc to try to clean up the memory every time the used memory limit exceeds.

Leave a Reply

Spam protection by WP Captcha-Free