1

I tried to find a similar question, but I didn't succeed.

In a bean, I'm looping through a ViewEntryCollection several times, adding or deleting entries. Could someone tell me exactly when these objects should be recycled? I want to be able to reuse the whole collection so I don't want to destroy any objects I might still need.

My code:

public static int FTSearchAll(ViewEntryCollection vec, View vw, String cat, String query) throws NotesException {
    ...
    for (ViewEntry ve = nav.getFirst(); ve != null; ) {
        ViewEntry next = nav.getNext(ve);
        Document doc = ve.getDocument();
        if (doc == null)
            continue;
        try {
            Vector v = session.evaluate(query, doc);
            if (v != null && v.size() > 0 && (Double) v.elementAt(0) != 0) {
                vec.addEntry(ve, false);
            } else {
                for (ViewEntry dce = vec.getFirstEntry(); dce != null;) {
                    ViewEntry dcnext = vec.getNextEntry(dce);
                    if (dce.getNoteID().equals(ve.getNoteID())) {
                        vec.deleteEntry(dce);
                        incinerate(dce);
                        break;
                    }
                    dce = dcnext;
                }
            }
        } catch (NotesException ne) {

        } finally {
            incinerate(ve, doc);
        }
        ve= next;
    }

As always: thanks!

D.Bugger
  • 2,300
  • 15
  • 19

2 Answers2

1

The rule is quite simple: when a Java object pointing to a Notes C object is about to go onto the garbage heap, .recycle() must have been called. So you need to do that for all entries inside the loop. My little rule of thumb: the block (think { ... } ) that created a Notes Java object must call its .recycle() function at the end. Saves you lot of headaches

stwissel
  • 20,110
  • 6
  • 54
  • 101
1

I see this, but not completely sure whether I miss something or the code keeps its functionality... :S

    for (ViewEntry ve = nav.getFirst(); ve != null; ) {         

        ViewEntry next = nav.getNext(ve);
        Document doc = ve.getDocument();

        if (doc == null) {
            incinerate(ve);             // << new
            ve = next;                  // << new
            continue;               
        }

        try {           

            Vector v = session.evaluate(query, doc);
            if (v != null && v.size() > 0 && (Double) v.elementAt(0) != 0) {
                vec.addEntry(ve, false);
            } else {
                for (ViewEntry dce = vec.getFirstEntry(); dce != null;) {

                    ViewEntry dcnext = vec.getNextEntry(dce);
                    if (dce.getNoteID().equals(ve.getNoteID())) {
                        vec.deleteEntry(dce);
                        incinerate(dce, dcnext);       // << new                    
                        break;
                    }
                    incinerate(dce);                // << new
                    dce = dcnext;

                }
            }

        } catch (NotesException ne) {

        } finally {             
            incinerate(ve, doc);                
        }

        ve = next;
    }

Maybe it would be better to check another implementation.

Anyway, I recommend you to use the OpenNTF Domino API and get rid of recycle, and you will get also a proper iteration over entries: http://www.openntf.org/main.nsf/project.xsp?r=project/OpenNTF%20Domino%20API

Txemanu
  • 449
  • 2
  • 7
  • Gee, the OpenNTF Domino Library... Thanks, I really didn't know it doesn't need recycling... Makes me feel kind of stupid... :-$ I think I'll try to convince my client to adopt this API. – D.Bugger Apr 17 '15 at 13:02
  • Small (big) problem with the ViewEntryCollection class in that library: there is no proper way to use it when you have to remove entries (NullPointerException). – D.Bugger Apr 27 '15 at 12:00