Using Notes objects in XPages and in Java require that you recycle those objects in order to avoid memory leaks and backend out of memory issues. Here I will summarize how to do proper recycling in XPages for server-side javascript, Java and Java using the new OpenNTF project org.openntf.domino.
Server-side JavaScript
With server-side JavaScript you have to use the recycle method available on Notes objects and you have to “nullify” your server-side JavaScript variables. Thank you, Tony McGuckin, for clarifying this.
Here’s a very simple example that assumes that the variable doc has been initialized elsewhere:
doc.recycle(); doc = null;
Java
In Java you have to use the recycle method available on Notes objects. So for looping through a document collection you have to do this:
try {
Database dbCurrent = ExtLibUtil.getCurrentDatabase();
DocumentCollection dc = db.getAllDocuments();
Document doc = dc.getFirstDocument();
While (doc != null) {
// process doc
tmp = dc.getNextDocument(doc);
doc.recycle();
doc = tmp;
}
dc.recycle();
} catch (NotesException e) {
e.printStackTrace();
}
org.openntf.domino
With org.openntf.domino you do nothing with regards to recycling! So when looping through a document collection you can concentrate on your business logic:
Database db = Factory.getSession().getCurrentDatabase(); for (Document doc : db.getAllDocuments()) // process doc }
