1
我在這裏有一個奇怪的問題,告訴我有些數據庫對象是在下面顯示的方法中發佈的,儘管至少沒有數據庫連接。數據庫對象是由GC發佈的,沒有先關閉
控制檯輸出:
SOMETIMES I DROP GC stuff
WITH FILENAME stuff
WITH FILENAME stuff
WITH FILENAME stuff
**** WARNING! Database object was released by the GC without being closed first! This might cause crashes on iOS *****
**** WARNING! Database object was released by the GC without being closed first! This might cause crashes on iOS *****
**** WARNING! Database object was released by the GC without being closed first! This might cause crashes on iOS *****
WITH FILENAME stuff
WITH FILENAME stuff
WITH FILENAME stuff
AND GC stuff is somewhere here
和相應的方法
@Override
protected boolean initListModelPhotoList(List cmp) {
Integer imgHeight = Display.getInstance().getDisplayHeight()/10;
Image placeholderImg = fetchResourceFile().getImage("camera_placeholder.png");
System.err.println("SOMETIMES I DROP GC stuff");
Storage storage = Storage.getInstance();
Vector vector = new Vector();
for (xyz.model.Image image : images) {
if (!image.getDeleted()) {
Hashtable tableItem = new Hashtable();
Image img = null;
try {
if (!storage.exists(image.getFileName())) {
img = placeholderImg;
tableItem.put("icon", img.scaled(imgHeight, -1));
} else {
InputStream is = storage.createInputStream(image.getFileName());
img = Image.createImage(is);
// tableItem.put("icon", img.scaled(imgHeight, -1));
is.close();
System.err.println("WITH FILENAME stuff");
}
tableItem.put("emblem", image.getFileName());
tableItem.put("sort", image.getSort());
} catch (IOException e) {
e.printStackTrace();
}
vector.add(tableItem);
}
}
System.err.println("AND GC stuff is somewhere here");
cmp.setModel(new com.codename1.ui.list.DefaultListModel(vector));
return true;
}
我甚至嘗試做一個close()方法和Util.cleanup(是)上的InputStream檢查是什麼問題這裏。通常我的實現是Storage.getInstance()方法中的每個調用。
當我在其他部分Inputstream is
後發表評論行,我不在控制檯
得到這樣的消息,以便在問題IM詢問這裏是否有一種方法的誤用,或者如果我可以忽略這?
前段時間我重構了我的DAO方法來優化和修復代碼,但是在您的消息之後,我確實可以找到一個未正確關閉的方法,之後錯誤仍然存在,但它只出現一次。現在深入一點,我可以再次改進代碼,我認爲它現在已經消失了。 編輯:錯誤是躺在一個方法調用DAO,並循環通過返回的對象,在這裏另一個DAO打開並調用子對象。這就是爲什麼我監督和忘記關閉(Y)。錯誤也出現在'initList'調用之前調用的方法中 – kaya