How to recycle Notes objects in XPages and Java

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
}

OpenNTF webinars for the open source community

logo

OpenNTF has announced a new initiative called OpenNTF Webinars.

The first webinar takes place tomorrow, Tuesday May 7, and is all about OpenNTF. Join the web meeting and hear Bruce Elgort, Serdar BasegmezJesse Gallagher, Niklas Heidloff, Peter Tanner and me talk about OpenNTF and about what OpenNTF can offer the open source community.

Future webinars will be announced at the webinar landing page.

Using an existing SSL certificate on IBM Domino

A customer of mine had an existing wild card SSL certificate running on IIS. They wanted to use this wild card SSL certificate for their IBM Domino server.

I had all the SSL certificate files available (the trusted root CA, the certificate and the private key). So I quickly found the guide from Gab Davis and did something similar: I created a key ring using the Server Certificate application on the Domino server and installed the trusted root certificate into the key ring. I then opened the key ring file in the gsk5 version of iKeyman (on Windows XP in order for it to run) but ran into the issue that I was unable to import the private key (.pfx).

The solution was to import the private key file in the Certificates program (certmgr.msc) by opening the private key file (and providing the password for the file and selecting the option to mark the key as exportable). Once imported I then exported the same private key as PKCS#12 (.pfx) and I was now able to import the private key as a personal certificate in the gsk5 version of iKeyman.

I saved the updated key file, added it to the IBM Domino server, and HTTPS was then working as expected.