开发者

GC.Collect call and OutOfMemory

When I 开发者_如何学运维call GC.Collect all works fine. But if I comment this call, I time from time receive OutOfMemory. Looks very strange. How to find this bug ?

Additional info Application sulution has some projects that have references to different frameworks from 2.0 to 4.0 Aplication is a windows forms application, devexpress is used.


The most likely variants:

  1. Large Object Heap fragmentation. In the application is used very big amount of collections of big size up to million elements, such as HashSet, Dictionary and etc. All of them call Array.Resize from time to time. So, GC.Collect does not solve the probem, just slows down the fragmentation.
  2. unmanaged code

Edited: 3. System.Drawing tends to throw OOM exception in some cases


You probably forget to dispose an object. Do you use any databases or other external resources?


If you have to call GC.Collect then something is wrong. You usually should not need to call the garbage collector.

  1. Try a memory profiler. This will show you how many objects of what type consume your heap.
  2. Check your unmanaged ressources. Every unmanaged resource has to be managed by a class implementing IDispoable in conjunction with a finalizer.


A common approach to debug memory leaks in .net is to use the SOS-Extension (you'll find some tutorials like this if you do some research) or to use a memory profiler, like this one. Maby you just forget to release (dispose) some unmanaged ressources?


I would try debugging managed memory issues with the CLR profiler.

Additionally, why are you calling GC.Collect() yourself? This is usually an anti-pattern.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜