search

Home  >  Q&A  >  body text

javascript - Problems encountered with js reference types under chrome

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梦2799 days ago868

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-05-19 10:46:03

    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;

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-19 10:46:03

    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

    reply
    0
  • Cancelreply