var a = new SomeObject();
a = null; // memory is freed
a = new SomeObject();
b = a;
a = null; // memory is not freed, as b still has a reference to it
What if I do this...
var city;
function onReceive(responseCode, data)
{
var message = data["message"];
city = data["name"];
}
will data never be freed?
In this example, city is a global. responseCode, data, and message are local to the onReceive function.
As soon as the onReceive function returns, the local variables (responseCode, data, and message) go out of scope and drop their references to the data they contain. city still contains a reference to the value that was associated with the "name" key in the data Dictionary. Whatever data was stored in that value will still have a reference held by city. The rest of the data that makes up the data Dictionary will no longer have any references and will be destroyed.