1) var x1:X = new X();
2) var x2:X = new X();
...
3) x1.z = new SWFLoader(...);
...
4) x2.z = x1.z;
5) x1.z = null
6) x1 = null;
The last statement is useless because statement 4 guarantees that x1 and anything else it contains will never ever be garbage collected as long as x2.z exists. Does anyone else think this is bizarre? This was a major shock and drawback to me for something that I needed to do. Is there any workaround at all?
The only reason this would make sense is if everything in x1 was stored in contiguous memory or something, but when you say "x1.z = new ..." in most languages that implies its going and allocating a new block of memory somewhere else and returning a pointer to it (a pointer that is subsequently assigned to x2.z as well.) I was always interpreting "reference" in actionscript as "pointer".
Of course some might say, well you could still delete everything in x1 individually. But if not for statement 4 above, statement 6 would mark everything in x1 for deletion.
(Note: the only reason I put statement 5 in was to tell flash player "I really don't care about x1.z anymore", but it made no difference.)