-1

There must be a secret in .NET garbage collection that I don't understand as for now. Our C# WinForms application has a dialog that loads very many objects via a OR mapper tool. This process consumes a lot of memory and we think that most of this memory could be consumed by strings. When we open this dialog, the task menager shows 900MB of memory usage and by doing the query again, we get a out of memory exception. Whow.

Now we got the tipp that some type of garbage collection is done when we minimize the application. By doing this and maximizing it again, the application only consumes 10MBs. Cool.

But now, when we do the query again, the memory consumption suddenly jumps back to 900MB and we get the out of memory exception again.

What happens here and how can we reduce our memory consumption? In such cases, how can the memory consumption be researched and reduced?

  • Have you used a tool such as ANTS Memory Profiler to see what objects are taking up so much memory? – Mike Christensen Oct 27 '11 at 22:49
  • 6
    Task Manager is _not_ the right tool to diagnose this. – H H Oct 27 '11 at 22:50
  • 1
    You answered your own question: don't use so much memory! – John Saunders Oct 27 '11 at 22:50
  • I'm not sure what you're asking here. When one wants to shrink memory usage, the obvious approach is not doing things that consume much memory (such as your query). If you allocate 900 MB's worth of objects, those 900 MB of memory got to be become available *somehow*. –  Oct 27 '11 at 22:50
  • Without an insight into your code this is a meaningless question. If you load 900 MB worth of text than that is what it costs. If you load (much) less then you're doing something wrong. – H H Oct 27 '11 at 22:51
  • The problem might be the used OR mapper that consumes much memory by mapping the single attributes. We have not used ANTS as for now, only Visual Studio performance wizzard which doesn't really help. – Peter Buchmann Oct 27 '11 at 22:54
  • @HenkHolterman: yes. Something is wrong and we for sure don't load 900MB of data, the 900MB that the task manager shows must be temp data maybe string used by the OR mapper but as they are temp data, the garbage collector should be somehow able to clean them up. – Peter Buchmann Oct 27 '11 at 23:03
  • 2
    Regarding the Task Manager oddity, see this question: http://stackoverflow.com/questions/2031577/can-memory-be-cleaned-up/2031886#2031886 – C. Dragon 76 Oct 27 '11 at 23:34

2 Answers2

0

Are you sure all your loops are completing. I know the biggest issue I have had with resources in my desktop applications have been loops that get stuck or do not end successfully. Are you sure your query is coming back correctly?

Are you doing more then just querying? I would make sure all your processes are starting and finishing correctly.

bvandrunen
  • 443
  • 1
  • 6
  • 15
  • Well we are using this OR mapper that usually works very fine. In this case something is wrong. We are loading the objects and then use Linq to create associations between some of them. – Peter Buchmann Oct 27 '11 at 23:27
0

There are a bunch of .Net Memory Profilers available to help diagnose issues like this. My favorite is dotTrace by JetBrains

Dylan Smith
  • 22,069
  • 2
  • 47
  • 62
  • It was really a problem that I could solve with a memory profiler. It had nothing to do with strings, it was a extensive use of subscribers that was not so easy to see in the code. – Peter Buchmann Oct 28 '11 at 19:52