[quoted text, click to view] Robert Tweed wrote:
> ActionScript uses reference counting (Flash 8 uses mark and sweep,
> but it's backwards compatible).
Just thought I'd add something to this. While the technique of setting a
variable to null to mark an object for deletion does work with mark &
sweep, it doesn't work instantly like it does with reference counting.
This means that anything that creates and deletes a lot of objects _may_
use different amounts of RAM depending on whether it's run on the Flash
7 or Flash 8 player, depending on how quickly the Flash 8 engine gets
around to deleting the unused objects. There's a good discussion about
the differences here:
http://www.kaourantin.net/2005/09/garbage-collection-in-flash-player-8.html A particularly good illustration from the comments is this:
Tinic Uro said...
"BIT-101: 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."
Of course you can't just reuse the space for an object if you want a
totally different type of object - in that case you'll still be invoking
the GC, perhaps without realising it. But this is a good example because
it shows a situation where you have a large number of objects, all the
same type, which are continually being "deleted" and "created", but in
such an instance, making your own mini memory manager for recycling
those objects is a good idea.
There isn't really any discussion of whether the same applies to movie
clips or not. For example, it might be better to put movieclips offstage
temporarily and reuse them instead of unloading and reattaching them,
but then again it might not. That's probably a situation that would call
for some profiling.