Is a Static Reference to an Object Garbage Collected?
If I declare a static reference to an object, will that reference remain in memory or will it eventually get garbage collected? I have a PropertyManager that has a static reference to a Properties object. This reference is set in the initialization process of the servlet after loading the Properties object from the property file. The PropertyManager is not a Singleton.
The code looks like this:
Class PropertyManager () {
private static Properties props = null;
}
public static void setProps(Properties props) {
PropertyManager.props = props;
}
In servlet:
FileInputStream fileConfig = new FileInputStream(servlet.getServletContext().getRea lPath(configFile));
Properties props = new Properties();
props.load(fileConfig);
PropertyManager.setProps(props);
When I try to reference the Properties object from other classes, will it still be there, or will it get garbage collected at some point? Do I have to declare this as a Singleton in order to keep it in the heap?
Any help would be appreciated!
|