MemoryFailPoint always throws an InsufficientMemoryException even when memory is available

前端 未结 3 1110
清歌不尽
清歌不尽 2021-02-06 01:33

I have written the following code to check for sufficient memory,

while (true)
{
    try
    {
        // Check for available memory.
        memFailPoint = new          


        
3条回答
  •  感动是毒
    2021-02-06 02:11

    Consider using the GC.GetTotalMemory method to determine the amount of memory available before and after calling:

    memFailPoint = new MemoryFailPoint(250);
    

    InsufficientMemoryException is thrown before starting an operation, by the MemoryFailPoint constructor when you specify a projected memory allocation larger than the amount of currently available memory. Like user7116 commented, that's why you should check first.

    The example in this link should give you a solution: MemoryFailPoint Class

    You can also check this msdn blog article: Out of memory? Easy ways to increase the memory available to your program

提交回复
热议问题