ShowTable of Contents
In XPages development, there are several layers of scoped variables which are some sort of implementation of Java hashmaps to store different objects. There are five levels of scopes in XPages. Refer to Scoped Variable in XPages
article for more information.
Storage in Scoped variables
Normally, Java Hashmaps provide no restriction storing objects. You can always store any object in a scoped variable:
Although it is legitimate, the storage of some objects are not good practices. Let's explore some aspects:
Notes objects like NotesDocument, NotesView, NotesDatabase, etc. are not based on SSJS or Java. At the bottom level, they are based on C-equivalents and they don't have automated garbage collection. So storing them into hashmaps will have toxic effects in the JSF cycles and memory management. Read Tim's comment
for more explanation.
You have to use primitive information about objects. For instance, if you want to store a profile document on applicationScope, the best practice will be using its universal ID. The same will be applied for view name instead of NotesView, database file path instead of NotesDatabase, etc.
First, we will explain the Serialization
concept: Serialization is the ability to convert some data structure to a type that can be stored to a file/memory buffer and/or transmitted over a stream.
When XSP server serves a page, it constructs a 'in-memory' tree structure. This tree-structure, we can call it as the page, contains many objects like div elements, viewScope, etc. The page is being used to operate between states and changes. In 8.5.1, this page was being stored in memory. If hundreds of users requesting the same page. Memory will be filled with hundred 'page's in memory for each request. That's why XPages consumes so much memory but it feels very fast after the initial launch.
However, XPages team creates an additional method to increase scalability. After 8.5.2, XSP server has the ability to store those pages in disk. It decreases the performance because of the increase in disk activity, but it improves the scalability which means you may serve more and more users with the same memory space.
XSP server is using serialization to store the page into the disk. So if you have objects that are not serializable in your viewScope, it will fail writing these pages into the disk and throws the error: "java.io.NotSerializableException: 'some object type'".
The most common type of unserializable object is SSJS functions. You may use them in the requestScope but any objects that are not serializable should not be used in higher scope. viewScope will certainly fail depending on the configuration. Although the higher scopes seem safe currently, this would be changed in the future for reasons like clustering.
Consider that 'Keep pages on disk' feature is the default option in newly created databases in 8.5.2. It can be changed under XPages tab in Application Properties page.
You may read more about this issue at the following blog topics: