You can configure a memory limit. The neuray system will try to keep its memory usage below that limit. To achieve this it will flush data to disk. Objects can be flushed if the system guarantees that other hosts in the network still have them or if they are the result of a job execution which can be repeated.
neuray can be configured to use a swap directory to which it can flush out the contents of database element. Those elements can then be dropped from memory if the memory limit was exceeded. They will automatically be reloaded on demand when they are accessed again.
The memory limits can be adapted dynamically. If you decrease the memory limit neuray will make a best effort to reduce the memory usage to the given amount. Actually enforcing this limit may take a while and is not guaranteed to succeed.
You can configure neuray to use a custom allocator object provided by your application. The allocator has to implement an abstract C++ interface class which exposes the functionality of allocating and releasing memory blocks. It also allows one to inquire about the amount of memory currently being used. Calls to the allocator object can be done from several threads at the same time, including those threads from the application which are currently inside calls to neuray. The allocator object must be implemented to handle this concurrency properly.
If the allocator cannot provide the memory requested by neuray it needs to signal this failure by returning a 0 pointer. In that case neuray will try to flush memory to accommodate the request and retry again. If this is not successful neuray will terminate and release the memory it uses, but it cannot be guaranteed that all memory will be released. Additionally in that case it is not possible to restart neuray without restarting the complete process.