When does garbage collection happen for a class with static data
garbage-collection, java, static
Solution
you can try to make it final, and recompile the code in order to see if some other class CHANGES the reference to null:
public class Global {
public final static List<String> data = new ArrayList<String>();
}
this allow to write:
Global.data.add("foo");
but not:
Global.data = null;
Problem
I want to make some data easily available throughout my application. I have a few variables in a class with static data, which get written to and read from at several different points. This worked fine for a while, but now at one point where I expect to be able to retrieve an ArrayList all I get is "null". I am wondering if the static class has been sent to the "garbage collector". Not sure what's going on, if you can help that would be much appreciated.