So I am pretty familiar with memory management in Java, C and C++; however, in flash what constructs are there for memory management? I assume flash has a sort of virtual machine like java, and I have been assuming that things get garbage collected when they are set to null. I am not sure if this is actually the case though. Also is there a way to force garbage collection in Flash? Any other tips?
Thanks
Flash bytecode is run by the AVM (Actionscript Virtual Machine). In general terms (and without being an expert in Java or the internals of the Flash Player), I think it’s safe to say that the AVM model is somewhat analogue to the JVM model (source code is compiled to bytecode, which is run by the VM; in AVM, at least, some of it is interpreted and some is JIT compiled to native code before execution, etc).
AVM is, as you said, garbage collected, so basically memory allocation and deallocation is managed for you by the GC. When an object becomes unreachable, it’s eligible for GC (which doesn’t mean it is collected right away).
There’s a way to force a GC cycle, only available in the debug version of the player, and also a hack, unofficial and undocumented, but you can find some links about it in google (try GC hack flash LocalConnection or something along those lines). Forcing a GC is almost always a bad idea though.
I’ve recently come across this blog post that explains how the GC works in some deatil, with references to the AVM C++ source code (that part of the player is open source, so you can check it out for more in depth info if you’re so inclined). http://jpauclair.net/2009/12/23/tamarin-part-iii-current-garbage-collector-in-flash-10-0/