Hi Peter,
Thanks again for an informative post. I meant by "fluffiness", "not knowing
when it will release memory" - and you're right, my term is rather
unhelpful!

)
You're also right that I was just going by some of the metrics displayed in
Task Manager. I now realise this is naive of me. The GC might only return
the memory when another memory allocation occurs. Since I'm running well
below the physical amount of RAM in the system, I really haven't tested this
very well!
Thanks again...this marks another notch in my (rapidly) improving
understanding of .NET and I appreciate yours and others patience in advising
this (otherwise experienced Win32) developer!
Regards,
Alain
"Peter Duniho" <(E-Mail Removed)> wrote in message
news:1m3dwcpm2ib9$.(E-Mail Removed)...
> On Fri, 3 Feb 2012 16:40:25 -0000, Alain Dekker wrote:
>
>> Hi,
>>
>> I know the automatic garbage collection is supposed to be "better" but
>> having spent my programming life looking after memory myself, I don't
>> like
>> the fluffiness of it. OK, rant over.
>
> "Fluffiness" being a well-know technical term, of course. 
>
> GC isn't uniformly "better" or "worse". It's "different". However, it
> _does_ address a particularly common type of programmer error, with little
> or no performance cost (and in fact in some cases can perform better).
>
> Back in the 90's when .NET and C# were first showing up, GC was my primary
> objection to .NET. But back then, GC-based systems were slow and
> annoying.
> They've come a long way since then, and I generally try to avoid
> programming without GC now. I spend WAY less time writing nuisance
> boilerplate code, and can focus much more efficiently on the code that
> makes each program unique. 
>
>> I display a startup form, then overlay another "main run screen" when all
>> startup actions are complete. As part of that startup I display a bunch
>> of
>> pretty images, changing on a timer tick event, in the startup screen.
>>
>> I've cached those images (they're embedded into the EXE) into an array
>> and
>> then cycle through the images as the startup goes on. Problem is that
>> when I
>> overlay the main run screen, the memory from these images is never
>> released.
>
> If that's really true, you have a programming bug. GC doesn't eliminate
> _all_ kinds of bugs. It just eliminates one particular kind.
>
>> Is there any way I can force C# to give me back the memory? There doesn't
>> seem to be any "delete" keyword like there is in C++ and its not going to
>> be
>> simple to convert the code into a "using" clause.
>
> You first need to be more specific. You can't fix a problem until you've
> got a well-defined description of it.
>
> In .NET (and similar systems), GC can't handle everything. Because the
> system interfaces with the OS and other components that don't themselves
> support GC, .NET provides mechanisms such as the IDisposable interface to
> coordinate deterministic resource releasing.
>
> Image objects generally fall into this category. Because there's
> unmanaged
> data (e.g. a Windows HBITMAP object) underlying the managed type, the
> managed type implements IDisposable and you need to call the Dispose()
> when
> you are done with the object.
>
> The GC also cannot release memory until it's no longer reachable through
> any of your program's data structures. If you create an array of objects
> but never release the array (e.g. by setting the array reference variable
> to "null"), then the GC thinks you still need the memory.
>
> Finally, you need to make sure you understand whether the memory truly is
> not being released or not. Nothing in your post suggests that you've
> actually done this. A common mistake is to look at the working set or
> other memory metrics in Task Manager or Resource Monitor and assume that
> just because the process memory allocation hasn't gone down that your
> memory wasn't freed.
>
> But that's not how it works in .NET, or even native C/C++ programs. The
> memory manager can grow your heap as you allocate memory, but then when
> your program releases objects that does not necessarily mean that the heap
> will shrink in size again. It _might_, but it also might not. For a
> variety of reasons, it is often advantageous to keep holding on to memory
> allocated from Windows, even though that memory is not currently claimed
> by
> any objects maintained by the program itself.
>
> For that reason, external measures of how much memory a program is using
> are not a good indicator as to whether memory is being released or not.
>
> So for all we know, you don't even have a problem.
>
> If you are sure you do have a problem, post a concise-but-complete code
> example that reliably demonstrates that problem. Be specific about how to
> reproduce and observe the problem.
>
> Pete