Can I trigger JavaScript's garbage collection?

后端 未结 9 2031
不知归路
不知归路 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:44

    Yes, you can trigger garbage collection by re-loading the page.

    You might want to consider using a Factory Pattern to help re-use objects, which will greatly cut down on how many objects are created. Especially, if you are continuously creating objects that are the same.

    If you need to read up on Factory Patterns then get yourself this book, "Pro Javascript Design Patterns" by Ross Harmes and Dustin Diaz and published by APress.

提交回复
热议问题