Tip

Recycle the right way

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.

This was first published in March 2004

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.