Search code examples
javaxpagesrecycle

When do I need to recycle?


I have an applicationScope managed bean that loads a bunch of information about a series of applications into a Map. Then the following method is part of the bean:

public Database getAppDB() {
    Database appDB = null;
    try{
       Session s = ExtLibUtil.getCurrentSession();
       serverName = s.createName(s.getCurrentDatabase().getServer()).getCommon();
       appDB = s.getDbDirectory(serverName).openDatabaseByReplicaID(this.getAppRepID());
       return appDB;
  }catch (NotesException e){
      System.out.println(e.toString());
      return appDB;
  }

}

Now this method declares two Objects (Session and appDB). Not sure if they need to be recycled before returning and if so how would one do that because appDB is the returned value. The Session can easily be recycled. Now clearly if I call this method from some SSJS:

var thisDB:NotesDatabase = appProps[ssApplication].appDB;

I need to recycle thisDB in the SSJS.

also if I do something like this in SSJS:

var cNames =  appProps[ssApplication].appDB.getView("vwFTSearch").getColumnNames();

I'm assuming that there is nothing to recycle?


Solution

  • Detailed answers are in other two questions Knut pasted.

    The short answer to your specific question is that you shouldn't recycle those objects in the getAppDB() method.

    Session will be automatically recycled after the page has been served. The database object should be recycled by the caller of this method (SSJS, for your case).