There is no free
command in JavaScript, so you cannot free memory yourself. All you can do is: Kill all links (pointers) to any object. In the end, the garbage collector will look for objects that are no longer visible to anyone.
Or rather: the GC will eventually collect all the memory that can still be achieved and forget about everything else. That's why the cost of living objects is in the GC environment.
But there is one catch: GC does not inform objects that they are dead. Therefore, if your Enemy object needs some cleanup, you must do it manually.
source share