Home > Back-end >  Return whether the object is also pass "value" of the object (clone)?
Return whether the object is also pass "value" of the object (clone)?

Time:12-12

Made a test, after instantiate the current instance also gave the static properties of a class, and then I put the static property=null, but instance itself is in, it is shows that the return object is the value transfer, also is to be the object of clone?

CodePudding user response:

You didn't make clear the relationship between objects and references, has nothing to do with the cloning,
First of all, you can't destroy objects, object only through garbage recycling,
So, you put the static property=null only static attributes this reference variable itself no longer points to the object, with the object itself exists no it doesn't matter

For example,
A. A=new A ();//a is a variable, in the stack, new a is an object, in a heap, quite a thread connecting new do you have a a
A, b=A.//b is a variable, a and b at the same time pointing to an object (new instances of a), b hand there is a thread connecting new a
And then you modify b=null;//that's just b is no longer the reference object, which is in the hands of line b and new A broken, but also A line in the hand is still there, still in A reference new A, so the object will not die
First you have to understand that variable assignment and object creation (die) are two different things, variable assignment will not necessarily create new objects (such as the above b=a, without a new object is created, so there is no what cloning), variable to null object with die, die whether the object is garbage collection management, garbage collector will determine whether the current object and other variable references, there are not recycling, not necessarily immediately if not, maybe just identified as can recycled objects



  • Related