问题描述
为什么我不能多次调用它?
private Document getStationery(String txtStationery,Database mailDB){
try {
View mailView = mailDB.getView("(Stationery)");
DocumentCollection dc = mailView.getAllDocumentsByKey("Memo Stationery");
Document tmpdoc;
Document doc = dc.getFirstDocument();
while (doc != null) {
if(doc.getItemValueString("MailStationeryName").equals(txtStationery))
{
return doc;
}
tmpdoc = dc.getNextDocument();
doc.recycle();
doc = tmpdoc;
}
} catch (NotesException e) {
// Todo Auto-generated catch block
e.printstacktrace();
}
return null;
}
在下面第二次使用时崩溃......与不回收有关吗?
public void send() throws NotesException,IOException,Exception{
Session session = getCurrentSession();
Database userDB = getUserDatabase();
Database mailBox = session.getDatabase("","mail1.Box");
Document stationeryDoc1 = getStationery("Test1",userDB);
Document stationeryDoc2 = getStationery("Test2",userDB);
解决方法
您可以尝试完全不回收(通常不是一个好主意,但在这里排除其他问题可能会有所帮助),或者正确回收 getStationary() 方法中的对象,从 Document、DocumentCollection 开始,最后是视图。目前,您回收的唯一对象是 while 循环中的前一个 Document 对象。