Can I trigger JavaScript's garbage collection?

后端 未结 9 2062
不知归路
不知归路 2021-01-31 07:17

I want to trigger JavaScript garbage collection. Is it possible? Why would I want to, or not want to, do this?

9条回答
  •  囚心锁ツ
    2021-01-31 07:51

    Garbage collection runs automatically. How and when it runs and actually frees up unreferenced objects is entirely implementation specific.

    If you want something to get freed, you just need to clear any references to it from your javascript. The garbage collector will then free it.

    If you explain why you even think you need to do this or want to do this and show us the relevant code, we might be able to help explain what your alternatives are.

提交回复
热议问题