简体   繁体   中英

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?

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).

The general rule is: you destroy (recycle) what you created. You leave what was given. Session and database are system provided objects (given), so you leave them alone even if you used a different function to obtain them.

For the rest i found a reasonable Practise: in the function that created the object it gets recycled, not anywhere else. You have to take the "created" a little pragmatic. Eg when you have something like:

 var custDB = getCustDB(curUser);

then you wouldn't consider getCustDB as the creator, but that line of code and have the recycle(); in the function where that code is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM