0

my window service will generate some text files and it will be placed in some mentioned folder on during process suddenly service gets stop and thrown this error

Error Text :Exception of type 'System.OutOfMemoryException' was thrown.

how to come out off this issue ...

NOTE: it was going for volume of 2000 - 3000 files

issue was receiving when about volume of 5000 means ... the above error was receiving

pravz
  • 235
  • 1
  • 7
  • 18
  • We noticed similar behaviour in one of our WCF services when hosted with IIS. The filestreams were all handled with using statements (disposed) I found an article (since lost) that mentioned that the IIS worker process wasn't brilliant in these circumstances for defragmenting the memory or even correctly unallocating in a timely fashion. We moved to a Windows Service to resolve the situation and to-date, we've not experienced the same issue. Interesting that you are getting similar behaviour from the Windows Service though... – Smudge202 Jul 12 '11 at 13:14
  • Are you not disposing your FileStream ? – shenhengbin Jul 12 '11 at 13:17

1 Answers1

0

Typically Out of Memory Exceptions indicate something is not being properly disposed. Make sure anything you are using that is IDisposable is getting disposed when you are done with it, and you are not holding on to these resources longer than you absolutely need to be.

The best way to track down these issues is with the help of a Memory Profiling tool. The general idea is to take snapshots of memory usage and compare them, trying to find things that are holding on to memory that shouldn't be. I've used several tools, including DotTrace, ANTS profiler, .Net Memory Profiler, and they all have various strengths and weaknesses, but they generally provide a way to compare snapshots so you can see the deltas. More importantly they all have free trials, so you should be able to install one and start digging in to your problem.

If your interested, there is a StackOverflow Question about which profiler is best that while surly opinionated, should provide some good information about various tools.

Community
  • 1
  • 1
ckramer
  • 9,419
  • 1
  • 24
  • 38