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
}

Aptana: The Web IDE

Have a look at Aptana: The Web IDE. Aptana is a robust, JavaScript-focused IDE for building dynamic web applications. Highlights include the following features:

  • Code Assist on JavaScript, HTML, and CSS languages, including your own JavaScript functions
  • Outliner that gives a snapshot view of your JavaScript, HTML, and CSS code structure
  • Error and warning notification for your code
  • Support for Aptana UI customization and extensions
  • Cross-platform support
  • Free and open source

Please notice that the Aptana code assist feature has support for different popular AJAX Javascript libraries such as Dojo and Prototype.

The alpha version was released in March 2006 and Aptana is now in beta with the current version being 0.31. You can either download Aptana as a stand alone client or as a plugin for Eclipse.

I’ve tried the stand alone client and I really like the code assist and the integrated JavaScript and DOM documentation.

Using Ajax to manipulate Lotus Notes documents

Joachim Dagerot has published an article on developerWorks on using AJAX to manipulate Lotus Notes documents. From the article introduction:

Giving users instant feedback instead of the time-consuming page reloads they’re used to is simple when you use Ajax. Discover how a view and an agent can help you build Ajax-driven applications and learn how to define an API for getting the client and the Domino server to collaborate.

If Joachim is in the mood for an update to the article I would like to see how to do this using dojo as the Javascript Toolkit for the AJAX calls – especially considering the latest on IBM and dojo 🙂

Update: Joachim is in the mood and is asking for ideas on what to focus on with regards to Domino and dojo.

Firebug: a JavaScript, CSS, HTML and AJAX debugger

If you need a comprehensive JavaScript, CSS, HTML and AJAX debugger then you should have a look at Firebug. Firebug is a Firefox extension that “lets you explore the far corners of the DOM by keyboard or mouse. All of the tools you need to poke, prod, and monitor your JavaScript, CSS, HTML and Ajax are brought together into one seamless experience, including a debugger, error console, command line, and a variety of fun inspectors.

Firebug 0.4 was just released yesterday by the author Joe Hewitt.

I have had my problems debugging AJAX so hopefully Firebug can come to the rescue here.