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(); } }
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.