2

I am writing code for JS. And I need to know how works memory in JS when I remove big Object.

var a = new Object();
a.b = new Object();
a.b.c = new Object();
a.b.c.d = new Object(); 

a.b = undefined; // Is it delete a.b.c and a.b.c.d or not?
2

2 Answers 2

5

If there are no pointers to an object it will be garbage collected. Since the only pointer to a.b.c was in a.b, a.b.c will be garbage collected. Same situation with a.b.c.d.

Sign up to request clarification or add additional context in comments.

Comments

5

JavaScript is automatically garbage collected; the object's memory will be reclaimed only if the Garbage Collectior decides to run and the object is eligible for that.

The delete operator or nullify your object ( a.b = undefined; )has nothing to do with directly freeing memory (it only does indirectly via breaking references). See the memory management page for more details).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.