MemoryFailPoint always throws an InsufficientMemoryException even when memory is available

前端 未结 3 1046
清歌不尽
清歌不尽 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:10

    MemoryFailPoint checks for consecutive available memory as documented here : http://msdn.microsoft.com/fr-fr/library/system.runtime.memoryfailpoint.aspx

    You may consume very little memory, but have fragmented it a lot and then be now unable to allocate a consecutive block of memory of the needed size. It's very typical of this problem to occur after a few hours. To avoid that, use a pool of object for object you keep instantiating, it will make the memory space in use more rigid.

提交回复
热议问题