0

I have a global object 'm1' on my html5 web page. Here is how it's defined:

m1:
    {
        def: null
    },

I'm working with that object throught the game by adding more variables to it (actually it's graphic sprites):

m1.actor1 = new CreateSprite(...);

At some point of time I don't need m1 object anymore and ALL of the resources taken by its inner variables. Would that action tell garbage collector to totally erase it? :

m1 = { };

Does it mean that after this object recreation I get m1.actor1 erased as well?

Jeffrey.K.
  • 127
  • 1
  • 2
  • 7
  • What exactly does this have to do with javascript and HTML5 ? – adeneo Feb 25 '16 at 12:11
  • 1
    You should just search there are lots of posts: http://stackoverflow.com/questions/7437125/how-do-i-explicitly-release-a-javascript-object-from-within-the-object http://stackoverflow.com/questions/4523172/freeing-javascript-object http://stackoverflow.com/questions/742623/deleting-objects-in-javascript – lastboy Feb 25 '16 at 12:20
  • Objects are eligible for garbage collection when there are no remaining references to them. So yes, if you assign m1 to some *other* object then the original object can be garbage collected. Any secondary objects referenced by properties of the original main object can also be garbage collected - assuming no other variables refer to them either. (Note that this doesn't make the garbage collector run immediately, it just means that when it does it will collect those objects.) – nnnnnn Feb 25 '16 at 12:24

0 Answers0