If you want garbage collection in a variable to be included in Javascript, is it better to set it to null or undefined?

I am developing an Android game using the JS framework. I want to make sure that some objects are garbage collected as soon as I use them. How to make him? Should I use null or undefined?

+6
source share
3 answers

You cannot forcibly collect garbage (not within reasonable limits).

If your variables do not automatically go beyond, just set them to null .

+8
source

The best advice is to identify them in an area that makes them suitable for garbage collection. This means that you do not use global variables that never become available for collection. Instead, declare them as locals.

+5
source

You can set it to null, and if this is the last reference to this object, it will have the right to garbage collection.

http://coding.smashingmagazine.com/2012/11/05/writing-fast-memory-efficient-javascript/

TGH's suggestion is the best, although I would recommend it.

+4
source

Source: https://habr.com/ru/post/948746/


All Articles