Within a class that extends Thread, consider the following example:
public void run() {
while (workToDo) {
JSONObject json = new JSONObject(getNextMap());
publishJSON(json.toString());
// thread sleep
}
}
Is each instance of json still referenced as long as the thread is running, or are they freed each time new is called? Should this be moved to a method, i.e. publishJSON(getJson(getNextMap())?
whileloop, the object reference hold byjsonvariable will be marked for garbage collection.nullthe variable.