javascript - Problems encountered with js reference types under chrome
过去多啦不再A梦
过去多啦不再A梦 2017-05-19 10:44:03
0
2
873

Regarding reference types, value assignment is just a copy of the heap memory, that is, multiple variables point to the same heap memory. But under chrome, when I was testing, I encountered such a situation, I hope the experts can give me an answer

In the picture below

  1. I created a variable a and assigned an empty object to it

  2. Assign variable a to variable b

  3. aAppend an attribute name

  4. aLogout

According to the use of reference types, when a is canceled, the object should no longer exist, but b still has this reference. My question is this, shouldn't the result output by b be null, right?

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
小葫芦

For example:
a = {}; If the name of {} in memory is 0x2334c;
b = a; the actual execution is b = 0x2334c;
a = null; the execution is to mark a and wait for destruction;
But b still refers to 0x2334c, so 0x2334c is not destroyed;
Unless b and a = null;

滿天的星座

a and b both point to the same address c. Setting a=null only makes a no longer point to c. It does not destroy the data of c. However, b still points to c. There is nothing wrong

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template