We have an application where we totally cache huge volume of data. The cache is maintained as static maps.
Since the data is modified daily by some batch cycles, we refresh the cache after the data is modified. Refreshing cache is done by creating new objects and reference the static variable to these new objects. So each day new objects will be created and old objects are dereferenced.
But the problem is server heap memory keeps on increasing until one day it crashed without of memory exception.
I really doubt whether the dereferenced objects are garbage collected.
This is my class.
Class CacheService {
public static Map<String,Article> articleCache = null;
public docache(){
private Map<String,Article> tempArticleCache= new HashMap<String,Article>();
//Caching stuff
//finally
articleCache = tempArticleCache; // i hope defreferencing takes place here.
}
}
The function docache() will be called daily to update the cache. Could anyone help me achieve caching without this problem.