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.

This was first published in March 2004

Dig deeper on Java for Lotus Notes Domino

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.uk

Close