A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: [Flash8]Garbage Collection in Flash Player8

  1. #1
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666

    [Flash8]Garbage Collection in Flash Player8

    Maybe you know http://www.kaourantin.net, the blog of Tinic Uro ,principal Engineer of the Flash Player. It always features valuable information, so a good place to visit every few days.
    In this post http://www.kaourantin.net/2005/09/ga...-player-8.html Tinic explains the changes in the garbage collector made for flash player8. The changes in how the garbage collector work basically enforce what many flash game developers were already doing with things like the gotoandstop engine,i.e. reusing objects (where possible) instead of removing them and creating new ones. That is because the garbage collector doesn´t kill unused objects right away anymore.
    Tinic states this in a comment there:
    "One example: Particle systems. If you have objects representing particles, reuse the objects when they die instead of allocating new ones. Allocating large amounts of objects in a short time can kill the GC since unlike with the referencing counter model object are not freed right away anymore. So when objects die, put them into a recycle container from which you create more particles.
    "
    (If you keep that in mind you should be able to have better performance thanks to the way the garbage collector works now).
    thought this could be valuable info

  2. #2
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    didn't even know GC existed. It'll help me to code a little better, I think. I'm all for creating new and fresh objects, but i guess its not good practice.

    Thanks for posting that Tomsamson, http://www.kaourantin.net/ just favourited.
    lather yourself up with soap - soap arcade

  3. #3
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    yeah,a GC is something which is just there and people shouldn´t have to worry about it a lot
    Still its good to know in which way it works (in general) to trim performance requiring apps (like games) in a way in which they take advantage of the way the GC works.
    And yeah, Tinic´s blog is well worth beeing bookmarked =) .

  4. #4
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    This is for Flash8. If you publish for older players then GC works quite differently in those. At least that is what I read from the Tinic explanation.

    It could still be good idea to reuse objects.

  5. #5
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    sure its f8 specific, then again reusing objects wasn´t bad dev manner in f7 and older either (as it shows in the gotoandstop scroller concept, reusing objects also speeds things up for other reasons), so i think its good to reuse objects where possible no matter for which f player =)

  6. #6
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    I'm just a tad confused by this whole idea. From what I understand, the new garbage collector will hold on to items in an attempt to reuse them. Does that mean we should just keep removing and attaching clips, or manually reuse them?

    It sounds like FP8 does the work, but are we supposed to "help" ?

    Thanks for any clarification.

    Sounds very interesting, and I have thought of reusing clips and such, just never got around to it... like a lot of things .

  7. #7
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    i guess it's up to the developer. If your going to create a game which features heaps of effects you'll probably want to re-use those objects. Like when a spark fades or dies, rather than creating a new spark just use the same spark but load up its inital properties.
    lather yourself up with soap - soap arcade

  8. #8
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    Quote Originally Posted by UnknownGuy
    I'm just a tad confused by this whole idea. From what I understand, the new garbage collector will hold on to items in an attempt to reuse them. Does that mean we should just keep removing and attaching clips, or manually reuse them?

    It sounds like FP8 does the work, but are we supposed to "help" ?

    Thanks for any clarification.

    Sounds very interesting, and I have thought of reusing clips and such, just never got around to it... like a lot of things .
    Ok,let´s try to get things sorted =)
    First the new GC doesn´t hold things in order for em to be reused.
    It just holds them for a while as it works more like the GC of Java.
    That has many advantages as Tiric explains in his blog entry.
    FP8 does the work with the GC, we can do our stuff in a way i´n which it runs fine with the way the GC works.
    That means that we can for example reuse mcs (where possible) instead of constantly removing and attaching them.
    (Because otherwise if you would constantly create and remove a lot of objects the removed ones would hog up the memory till the GC has its next clearing run).

  9. #9
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    good explanation mr_malee,also speedier than mine

  10. #10
    Senior Member sand858's Avatar
    Join Date
    Aug 2001
    Posts
    327
    Nice post, tom.
    gamedozer games
    Free multiplayer and singleplayer games

  11. #11
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    If the point of the garbage collection is hold things to be reused, why does it matter if you keep removing and attaching clips, or anything? From what I understand, it keeps it for awhile and then dumps it, and the idea is not to give it anything to hold, but won't it just automatically do that for you?

    Hope that didn't come out wrong, but from what I understand(which is likely wrong ) the whole purpose is to hold things, so what is the purpose of manually doing it?

    I just had a thought, is what I am not understanding is that everything is in the garabe collector or just things that are deleted or removed?

    It sounds very interseting, I just can't quite grasp the concept.

    Excuse me if I was too harsh.

    Thanks!

  12. #12
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Noticed an article at MM about player speed and GC:
    http://www.macromedia.com/devnet/fla...rformance.html

  13. #13
    Senior Member webgeek's Avatar
    Join Date
    Sep 2000
    Posts
    1,356
    Hmmm, good to know, thanks for posting this. If people are curious to see how code should be created to avoid garbage collection load, looking into "pooling".

  14. #14
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    yeah,goodie


    Quote Originally Posted by UnknownGuy
    If the point of the garbage collection is hold things to be reused, why does it matter if you keep removing and attaching clips, or anything? From what I understand, it keeps it for awhile and then dumps it, and the idea is not to give it anything to hold, but won't it just automatically do that for you?

    Hope that didn't come out wrong, but from what I understand(which is likely wrong ) the whole purpose is to hold things, so what is the purpose of manually doing it?

    I just had a thought, is what I am not understanding is that everything is in the garabe collector or just things that are deleted or removed?

    It sounds very interseting, I just can't quite grasp the concept.

    Excuse me if I was too harsh.

    Thanks!
    the garbabe collectors task isn´t collecting objects so they can be reused.
    The task of it is to clear garbage (unused) elements so that ram is freed and can be used for other things (so if there wasn´t something like a garbage collector each application would lead to a crash after a while as ram would get filled up).
    In older flash versions the garbage collector worked in a way in which it gave a reference count to each object and deleted objects if their reference count was 0. The good side of that system is that it instantly deletes objects with a reference count of 0,so in ideal case ram would get freed instantly.
    But things are not always like in ideal case scenarios, more often that concept lead to problems and actually wasting memory as each and everything needs a reference count and those have to be raised/lowered all the time,too.
    (Trinic explains that better and longer in his blog entry, so maybe you can read up the downsides of the old garbage collector workflow there).
    Well, in flash player 8 the garbage collector works in a new,more java like sheme which means it doesn´t use reference count and instead removes unused objects incrementally in certain time frames.
    (Again why this is good is explained in Trinic´s blog, you can also read about the Java GC via Google or check the macromedia page regarding the GC).
    For flash coders this just means that you should be aware of the fact that unused objects aren´t instantly cleared, so its wiser to reuse objects instead of constantly adding new ones and removing old ones.
    Last edited by tomsamson; 09-29-2005 at 04:55 PM.

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