1

Let's say I have a function with a static property, for example:

function Test() {}

Test.someProp = bigObject;

I'm wondering if bigObject will always be in memory or it will gc sometime?

2
  • 2
    Once nothing has a reference to Test anymore, it should be GC'd, including the bigObject, as long as nothing else has a reference to bigObject either Commented Sep 21, 2018 at 10:23
  • It works that way even with static properties? Commented Sep 21, 2018 at 10:23

1 Answer 1

1

It will never be collected as long as someProp is alive (has a reference). If you delete Test.someProp or delete or empty the whole Test then it will be gCollected

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

6 Comments

So what you are saying is that if the code will stay like this, it will never be collected?
@CertainPerformance doesn't think like you, how can I know who's right?
Study! But really, he does say the same thing.
"Once nothing has a reference to Test anymore" - I'm not sure he says the same thing. @CertainPerformance can you clarify please?
Test belongs to global scope, so it already has a reference there.
|

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.