The solution that I ultimately chose was to set the maximum value for the amount of memory that appPool was allowed to consume. Then the code simply swallowed the memory until asp.net decided to recycle appPool.
In the advanced settings of the application pool, I set the limit of private memory to 800 000 Kb.
In the Catch section where the Linq code crashed, I allocate more memory than the limit:
List<string> listOfMemory = new List<string>();
Now this means that only about 4 threads fail before a new w3wp process arrives. Prior to this decision, threads will successively fail until a person manually processes the application pool. Unfortunately, if you configured the application pool to be reused in the usual number of minutes, the fewer the number of minutes, the more often the crash occurs. And the more minutes, the more threads will fail.
This workaround limits damage.
source share