Search code examples
javaxpagesrecycle

Issue of object.recycle, and when to do it


I have been fairly rigorous in recycling Notes Objects, but I have run into a situation where I can't recycle the object because it is passed back from a method to the calling code. So in a class I have this code:

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;
            }finally{
                Utils.recycleObjects(s);
            }

        } 

Which openes a database then passes the appDB back to the calling program. Clearly if I instantiate the database in my calling program I will need to recycle it, but in this class method I can not recycle it because it is getting passed back. Am I creating a ticking time bomb with this? If so is there a way around the issue? This method could be called hundreds of time over the life cycle of session.


Solution

  • Simply: the code that calls your method is responsible to recycle the database object. This rule applies to SSJS code too!

    You must not recycle the session either, because it recycles all object derived from it.