【发布时间】:2014-05-21 09:27:01
【问题描述】:
我的整个系统都有一个静态 HashMap,其中包含一些对象的引用;我们称之为myHash。这些对象仅在我需要它们时才被实例化,例如
private static HashMap<String, lucene.store.Directory> directories;
public static Object getFoo(String key) {
if (directories == null) {
directories = new HashMap<String, Directory>();
}
if (directories.get(key) == null) {
directories.put(key, new RAMDirectory());
}
return directories.get(key); // warning
}
现在,Eclipse 在 return 语句中告诉我一个警告:
Potential resource leak: '<unassigned Closeable value>' may not be closed at this location
为什么 eclipse 会这样告诉我?
【问题讨论】:
-
能否提供
myHash字段声明? -
whatever是什么?如果你能把它变成一个简短但完整的例子来演示这个问题,那么帮助你会容易得多。
标签: java memory-leaks lucene hashmap