About garbage collection in Flash

xiaoxiao2021-03-06  62

I have seen the mysterious Garbage Collection of Luar, there is slightly different opinions

Var Ref1: Object = new object ();

Ref1.name = "luar";

REF2 = Ref1; // Copy new Reference to another Variable

Delete Ref1; // then delete Ref1

Trace (ref1.name); // Output: undefined

Trace (ref2.name); // Output: Luar

I haven't learned the object-oriented language, I have learned C, the above code is in my opinion of the rules of GC. What is done above is:

1. Use new object () to generate an anonymous object, returning the location of the object in memory (the pointer in C) If there is no steps below, this object will soon be used as garbage by the Flash party, that is, the code is not meaningful:

New Object ();

But he is actually syntax that conforms to ActionScript.

2. Create a REF1 variable and let the REF1 value is the memory address 3 of the anonymous object above, create a REF2 variable, and let the Ref2 value of REF1 - actually the memory address of anonymous objects, then REF2 and REF1 are not directly Relationship, they just point to the same address, so deleting REF1 / REF2 does not affect the REF2 / REELETE RELETE RELETE RELETE RELETE; the role: If there is no Ref2, the above anonymous object is only referenced by Ref1, when Ref1 is delete This anonymous object will disappear; and the emergence of REF2 has caused the Ref1 after being referenced by DELETE, this object will not be recycled, and the REF2 continues to be valid.

When the same reason is also suitable for function, function () {} is also an anonymous function object, returns a pointer. Some bite is chewed, huh, huh, but I understand the garbage collection is like this.

As for the recovery of MovieClip, it does not meet the rules of garbage collection, and there is also a view in the authority guide of MOOCK, agree with Luar's views.

转载请注明原文地址:https://www.9cbs.com/read-88581.html

New Post(0)