March 30, 2012

Recycle() XPages repeat control?

I`m currently looking into memory management in Lotus Notes XPages applications. I understand that ideally every domino object should be recycled, especially when looping large collections and new`ing up large amounts domino objects.

What about the xp:repeat control? When I set a large NotesViewEntryCollection as value for a repeater (by just calling database.getView('x').getAllEntries()), how should this be recycled? Does it have to be recycled? The documents are commonly used further on in the repeater by calling 'curItem.getColumnValues()[x]' to build up the xpages content.

3 comments:

  1. You shouldn't need to worry about setting a recycle when setting the value of the repeat. Basically, at the end of any request Domino will automatically recycle everything. That's why you shouldn't store Domino objects in scoped variables.

    When doing getAllEntries(), I believe it is only getting a pointer to the view entries, not necessarily loading the data for them all into memory. During the repeat, the XPages runtime will go and get just a subset defined in the rows property, starting wherever the pager tells it to start. After it's got those entries and retrieved whatever it needs to output content to the browser, it then recycles the database and all child elements, including your ViewEntryCollection.

    So you should not need to recycle anything and, as you say, if you do recycle them you'll hit problems when it tries to call curItem.getColumnValues()[x].

    When your looping, it loads the data for each ViewEntry into memory but, unlike LotusScript, doesn't fully remove the ViewEntry when you set that variable to the next ViewEntry. That's why you need to do recycle there. My undertanding is that in a repeat, the code is effectively doing a loop on (by default) the first 30 entries and probably handling recycling as it processes each.

    ReplyDelete
  2. My understanding is that recycling is really only an issue if you create a loop yourself.

    ReplyDelete
  3. Thank you both! So, what I actually need to recycle is Domino objects when looping in my server side javascript files (I don't use much lotus script in this application)?

    ReplyDelete