I'm wondering how to properly destroy an object in Javascript that contains an array among other data.
For example (this is the initial state of the object):
acme.models.nomination = {
recipients : [], // array will be added to later.
awardType: {}, // this object will be filled out later.
privacy: 'private',
...
};
As the application is used the nomination.recipients object will be added to, along with the other data elements. Is it enough to do the following to clear the complete object when finished with it:
acme.models.nomination = {};
or is this better (or overkill):
acme.models.nomination.privacy = undefined;
acme.models.nomination.awardType = {};
acme.models.nomination.recipients = {};
acme.models.nomination = {};
I'm thinking that the former statement (i.e. acme.models.nomination = {}
) is enough as this effectively makes the entire contents unreachable and hence eligible for garbage collection. However, I'd like to get other peoples opinions on this. BTW, the answer can be given in a modern browser context, let's say browsers post-Jan-2012, as I know memory management was a bit inconsistent in the past.