Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to prevent memory exhaustions in Notes using Java

Java In Notes

How to prevent memory exhaustions in Notes using Java

by  Troodos  Posted    (Edited  )
One of the things to be aware of when using Java in Notes is memory consumption. (Almost) All Notes java objects has a method called 'recycle()'. Use it!! Use this for 'garbage collecting' for Notes specific objects, and rather overdo it than not do it...

While LOOPING and selecting in e.g. documents from a view, the previous selected document will be kept in memory EVEN if overwritten/replaced with a new value. Why? I do not have a good explanation, but just accept that this is the way it is...(and save yourselves from memory exhaustion and other troubles...)

A good way of avoiding this is the following method, or variants over the same theme:

...
View view = null;// NotesView in LS
Document doc = null; //NotesDocument in LS
...
//Variables above initialized and 'not null'//
doc = view.getFirstDocument();
while (doc != null)
{
...
// Some action/statements on the main doc...
...
Document tmp = view.getNextDocument(doc);
if (doc != null) doc.recycle();
doc = tmp;
// tmp is not necessary to recycle, but I normally do that anyway just to be sure...
if (tmp != null) tmp.recycle();
}
...
// Finished with operation on view:
if (view != null) view.recycle();

// the 2 lines below is AGENT specific...
if (agentcontext != null) agentcontext.recycle();
if (session != null) session.recycle();
...etc...

This method should keep your agent or other java code running more stabile and with less 'leakage' in memory. One of the most frustrating messages on a Domino console is 'JVM can not execute agent. Out of memory'...

TrooDOS



Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top