什么原因导致.NET运行时抛出OutOfMemoryException?垃圾收集器的工作是在分配对象之前根据需要清理内存并释放内存;为什么它会出现内存不足?为什么会抛出OutOfMemoryException?
0
A
回答
1
我觉得这个blog post由Eric Lippert是相当丰富。其中提到的一点是(简化):内存不足异常通常与过程无法获得足够满足当前需求的内存块有关。可能有很多内存可用,但碎片太小而无法使用。
0
如果你使用的内存比你多,并且没有释放它......你最终会失去内存。 GC只会清除您不再参考的内容。
0
垃圾收集器的工作比在对象之后清理更复杂。 gc还必须意识到如何分配内存,确保适用于应用程序的所有不同部分的足够大小的块(考虑多个线程等)。
垃圾回收器还必须负责可靠地清理内存,并以不会对性能产生显着影响的方式进行操作,并确保它在尝试执行代码时不会在代码中引入更多“问题”决定什么内存可以回收和什么不能。
它是一个很大的工作,并且不容易或直接实施。
对于您的具体情况,OOM可能因各种原因而发生,但在相当良好行为的应用程序中(即不分配不合理大小的对象等)通常会发生,因为内存请求比GC合理调整可用的内存来完成它,并且GC不能足够快地重新分散碎块以避免失速。在这种情况下,GC不得不向应用程序报告和OOM,以防止更多请求发生积压并确保它永远赶不上。
相关问题
- 1. 为什么FileOutputStream不会抛出OutOfMemoryException
- 2. 为什么StreamReader.ReadLine抛出OutOfMemoryException?
- 3. 为什么会抛出NullPointerException?
- 4. 为什么会抛出NullPointerException?
- 5. 为什么会抛出ClassCastException?
- 6. 为什么会抛出IllegalMonitorStateException?
- 7. 为什么会抛出java.lang.classCastException
- 8. 为什么会抛出OOM?
- 9. 为什么会抛出IndexOutOfBoundsException?
- 10. 为什么会抛出IndexOutOfBoundsException?
- 11. C++为什么会抛出?
- 12. 为什么会抛出NullReferenceException?
- 13. 为什么会抛出StringIndexOutOfBoundsException?
- 14. SqlCommand ExecuteNonQuery抛出OutOfMemoryException
- 15. 为什么我会发生OutOfMemoryException?
- 16. GrayScale(ColorMatrix)会导致OutOfMemoryException。为什么?
- 17. 为什么NHibernate会抛出“StaleObjectStateException”?
- 18. 为什么VB.NET默认会抛出OverflowException?
- 19. 为什么getMatrixTrait(“transform”)会抛出DOMException:NOT_SUPPORTED_ERR?
- 20. 为什么映射器会抛出ArrayIndexoutofboundexception?
- 21. 为什么异常不会被抛出?
- 22. 为什么chrome会抛出canvas.toDataURL
- 23. 为什么PyMongo会抛出AutoReconnect?
- 24. 为什么System.Web.Hosting.ApplicationHost.CreateApplicationHost会抛出System.IO.FileNotFoundException?
- 25. 为什么null.equals(null)不会抛出NullPointerException
- 26. 为什么这会抛出异常?
- 27. 为什么会resources.getStringArray(int)抛出异常?
- 28. 为什么Iterator.next()会抛出ConcurrentModificationException
- 29. HTTPBuilder为什么会抛出“HttpResponseException:Bad Request”?
- 30. 为什么IsInRole会抛出错误?