What is the Difference between GC.GetTotalMemory(false) and GC.GetTotalMemory(true)

Posted by somaraj on Stack Overflow See other posts from Stack Overflow or by somaraj
Published on 2010-04-06T06:08:05Z Indexed on 2010/04/06 6:13 UTC
Read the original article Hit count: 333

Filed under:

Hi,

Could some one tell me the difference between GC.GetTotalMemory(false) and GC.GetTotalMemory(true);

I have a small program and when i compared the results the first loop gives an put put < loop count 0 Diff = 32 > for GC.GetTotalMemory(true); and < loop count 0 Diff = 0 > for GC.GetTotalMemory(false); but shouldnt it be the otherway ?

Smilarly rest of the loops prints some numbers ,which are different for both case. what does this number indicate .why is it changing as the loop increase.

struct Address { public string Streat; }

class Details { public string Name ; public Address address = new Address();

}

class emp :IDisposable {

   public Details objb = new Details();       

   bool disposed = false;
   #region IDisposable Members

   public void Dispose()
   {
       Disposing(true);
   }


   void Disposing(bool disposing)
   {
       if (!disposed)
           disposed = disposing;
       objb = null;           
       GC.SuppressFinalize(this);
   }


   #endregion

}

class Program
{       

    static void Main(string[] args)
    {        
       long size1 = GC.GetTotalMemory(false);
       emp empobj = null;          

       for (int i = 0; i < 200;i++ )
       {
          // using (empobj = new emp()) //------- (1)
           {
               empobj = new emp(); //------- (2)
               empobj.objb.Name = "ssssssssssssssssss";
               empobj.objb.address.Streat = "asdfasdfasdfasdf";
           }

          long size2 = GC.GetTotalMemory(false);


          Console.WriteLine( "loop count " +i + "  Diff = " +(size2-size1));

       }
    }

}

}

© Stack Overflow or respective owner

Related posts about .NET