Manage Learn to apply best practices and optimize your operations.

Recycle the right way

Find out the right way to recycle Java objects.

View expert feedback to this tip.

Recycling Java objects related to Domino has a great impact on code stability. But once you recycle, do it the right way. If you put your recycle code at the end of the Try block, once an exception is raised, no recycle code is executed. For that reason recycling code has to be put in the Finally block.

Session session = getSession();
AgentContext agentContext = 
session.getAgentContext();

try {

  // (Your code goes here) 

} catch(Exception e) {
 e.printStackTrace();
} finally {
 // recycle your objects HERE!
 try {
   if( session != null) {
     session.recycle();
   }
   if( agentContext != null) {
     agentContext.recycle();
   }
   ... and other objects too
 } catch( Exception e) {
   e.printStackTrace();
 }
}

EXPERT FEEDBACK TO THIS TIP

Domino doesn't clean up after Java like it does in LotusScript and new Java programmers may not be aware of the need and best place to recycle their objects. Julian Robichaux has two blogs that point out some of the finer points. Check out What You Don't Know About AgentContext Can Hurt You and More Thoughts About recycle()

-- SearchDomino.com expert

Do you have comments of your own? Let us know.

Dig Deeper on Java for Lotus Notes Domino

SearchWindowsServer

Search400

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury

SearchDataCenter

SearchContentManagement

Close