A while back, Tinic Uro posted some info about Flash 8 garbage collection. Link here. It was cool info, but it left me wondering if there is something we should be doing to make the most of its advantages, and avoid its drawbacks. Here is his answer:
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.
I ran into that earlier this week while programming. Seems like a good thing to keep in mind, so although Tinic already put it out there, it can’t hurt to make it more well known.
Although I really appreciate this kind of knowledge on the FP, but what’s a bit worrying is that GC processes should actually take away that kind of issues from the developer. The way this is explained is that we should actually should worry about it a bit (in some of the more extreme cases, that is) but when it does create a problem we don’t have the specific control over it (like you would in a language where you had to worry about GC yourself). I might be wrong on this view, am I?
I hear you. The best GC would be GC that you never have to think about and always works perfectly without missing a beat. I never really worried about such things in Flash 7. Apparently the benefits of this method are lower memory usage and faster performance, and the drawback is that if you don’t program “correctly” you can wind up actually damaging your performance. Tough call I guess. But that’s what we have now, so best to know about it.
I must say I prefer the GC as it is now. We, as programmers, would love to squeeze every cycle, every byte, of performance from the player – it may be fast now, but what about when we’ve reached it’s limits? I prefer having the ability to code in such a way as to take advantage of how the GC operates instead of having no options available to me.
I’ve long been an avid fan of refactoring to lower memory and cycle usage (all whilst coding the Simplest Thing That Could Possibly Work), and this gives me one or two more tricks!
After all, it’s what we want, isn’t it? More control?
My $0.2 🙂