A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Timer memory usage

  1. #1
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324

    Timer memory usage

    Hi

    Can anyone tell me why when you use a timer with a small interval that the memory usage goes up?

    E.g with this code (you'll need a text field called fpst on the stage):

    var fps:Timer = new Timer(20, 0);
    fps.addEventListener("timer", fpsHandler);
    function fpsHandler(event:TimerEvent):void {
    fpst.text = System.totalMemory;
    }
    fps.start()

    Wait a few seconds and the memory usage will go up. If you increase the value from 20 to 200 the memory will still go up but very very slowly.

    Is this known behaviour? Im building a game which uses the timer to execute code everyframe so I need it to execute very fast.

    Is there another solution? I dont want to use enterFrame handlers.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I don't think it is a lot, because an empty movie already uses 7311360 bytes memory.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    Why dont you want to use enterFrame if you want something to happen every frame?

  4. #4
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324
    If you change the value to 1 you can see the memory usage going up faster. If the movie is run for hours (which, as it will be used in a game it will be) it would cause the computer to eventually crash.

    Should I consider this a bug with Flash 9?

  5. #5
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324
    I've also tried using weak referencing (i think) using this code :

    var fps:Timer = new Timer(20, 0);
    fps.addEventListener("timer", fpsHandler, false, 0, true);
    function fpsHandler(event:TimerEvent):void {
    fpst.text = System.totalMemory;
    }
    fps.start()

    and tried waiting 10 minutes to see if the Garbabe collector would delete whatever it is causing the memory to go up but to no avail.

    What am I doing wrong? I assume a lot of flash game developers use timers...

  6. #6
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    What version of the player are you using?
    It looks like this might be fixed in the next update (though I have not tested over prolonged periods of time).

    ... actually 9r28 seems to be handling it pretty well too.

  7. #7
    Member
    Join Date
    Mar 2007
    Posts
    33
    I think memory is going up because of all the timer event objects that get created.
    The garbage collector is lazy and it can take a few minutes before it kicks in. I see it in my project, where memory usage goes up all the time, and once it gets to a certain point some of it gets reclaimed by the gc, and usage starts going up again.
    Don't worry about it, if you wait long enough memory will get freed.

  8. #8
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324
    Thanks for the info! I hope you're right.

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