It doesn't necessarily have to go to Gen 2. If the arrays that the
RawBitmap instances point to are large enough (the OP says that it holds a
huge array of bytes), then those might go to the Large Object Heap.
As for calling GC.Collect, it's not the best in ASP.NET environments.
ASP.NET apps get into a more predictable routine for GC than say, windows
apps (which have more erratic spikes when it comes to allocating and
deallocating memory). Calling GC.Collect will disrupt that routine.
And for what? You (the OP) are using Task Manager to gauge whether or
not memory is being released. Task Manager only reports the ^working set^
to you, and not whether or not your memory is being collected properly.
If you are going to performance tune an ASP.NET application, you need
to know what to look at. In this case, it is the performance counters in
.NET, not Task Manager. If anything, you ^should^ see the value in Task
Manager increase. I'd almost say that if it wasn't as you do work, there
was something wrong.
Here is a link to a list of performance counters which would be of help
to you:
http://msdn2.microsoft.com/en-us/library/x2tyfybc.aspx
And by all means, take out the call to GC.Collect in your Dispose
implementation. It's not helping you. In fact, you are probably going to
see a drop in throughput as a result.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Jon Skeet said:
That suggests it's reached generation 2 - it would eventually get
collected, but there's nothing to trigger garbage collection
automatically at the end of the page lifecycle.
I *think* you'd have found that after a fair number of requests, the GC
would have collected the array.
Jon