A few reasons for why it is difficult (for me) to give focussed, goal-oriented advice:
It is not yet entirely clear what the actual, underlying reason for the error is. You suggested that it is related to the system running out of memory, and that may indeed be the case. But we don’t have the possibility to analyze this in the actual environment where the problem appears. Therefore, every attempt to solve the problem will involve some guesswork. And we have already seen examples of such guesswork:
- The problem might be caused by the garbage collector not running often enough or early enough. You mentioned “…we can’t run the garbage collection because it reduces the performance of the application”, but … well, when you allocate memory indefinitely, then it will of course crash. At some point, garbage collection (used as a synonym for “freeing memory”) has to happen. The questions that have to be answered in order to find a sensible solution are: Who has to release which memory at which point in time under which conditions?
- The original question was about controlling the number of loaded tiles. The maximum screen space error is the main mechanism for controlling that. Althought there is no direct relationship between this value and the number of loaded tiles, so it will require some experimentation. You cannot say which value you have to use to reliably prevent the crash (i.e. to reliably stay under a certain total allocation amount).
- The caching that is controlled via the
maximumCachedBytes
may have an impact, but tweaking it will not solve the underlying problem, if the problem is just that too much data is loaded - The idea of loading tiles with a higher detail in a certain radius will also not solve the problem, because you don’t know which radius and which level of detail you can use before it crashes.
Of course, it would be great if we could just insert some if (occupiedMemory() >= 0.9 * availableMemory()) doNotLoadThatTile();
somewhere, but … it’s not that simple, and without a careful analysis of the problem, every attempt to solve it may just consist of exposing parameters that can be tweaked (and where tweaking them might alleviate the problem), but not solve it in a reliable way.