>I think that the debugger causes this.
>
> I can see the difference :)
Don't bother! Debug mode is very different. It adds code to keep objects
around. Do you really want your unreferenced objects to disappear while
you're trying to look at them in debug mode? Debug mode would be impossible
if your objects were being collected. In general, GC in debug mode follows
scope rules.
You can't do any memory testing with debug builds!

Signature
Phil Wilson
[Microsoft MVP-Windows Installer]
>>I think that the debugger causes this.
>>
>> I can see the difference :)
>
> Thanks! I'm going to start a new thread over in
> microsoft.public.vsnet.debugging.
Mike King - 19 May 2006 18:09 GMT
Thanks for the feedback.
I'm only talking about a "Release" build.
Yes, I would like the GC to collect unreferenced objects because if there is
not reference, then I cannot inspect it so what is the point. Also, how can
one inspect variables of a "Release" build anyway? I posted the following
to microsoft.public.vsnet.debugging.
#### BEGINNING OF MY PRIOR POST ####
I think I have figured it out. I _think_ Visual Studio 2003 is holding a
reference to reference types that are directly assigned to variables of a
method even if out of scope. The only exception is in a "Release" build and
the application is started without debugging. The code below is a simple
example of this behavior.
using System;
class Class1
{
[STAThread]
static void Main(string[] args)
{
WeakReference wr = null;
for (int i=0; i<1; ++i)
{
Uri uri = new Uri("http://domain.com");
wr = new WeakReference(uri);
}
System.GC.Collect();
Console.WriteLine(String.Format("IsAlive: {0}", wr.IsAlive));
Console.ReadLine();
}
}
> Don't bother! Debug mode is very different. It adds code to keep objects
> around. Do you really want your unreferenced objects to disappear while
[quoted text clipped - 10 lines]
>> Thanks! I'm going to start a new thread over in
>> microsoft.public.vsnet.debugging.