문제

What is the best ways to get notified about the critical memory usage / remaining available memory? I'm currently working on a cache implementation, where cache size should adapt dynamically to available memory.

도움이 되었습니까?

해결책

You can use GC.RegisterForFullGCNotification() so that you will get notified when a full GC collection is imminent. See Garbage Collection Notifications on MSDN for details.

This doesn't really tell you that memory is getting low, but it does give you a good place to check it. However, it doesn't tell you when a lot of memory has been freed up so it might not be totally useful for you.

You could also look into the MemoryFailPoint class. This doesn't give you notifications, but it does let you determine if a memory allocation is likely to fail, before you actually allocate it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top