J
John Jenkins
Hi,
I have been working on a small C# project. As part of my testing I have been profiling the memory usage, and instances of classes created. I have tried to be careful to dispose of any objects that use Unmanaged code. As an example I have been using the MemoryStream object, however when I use it I wrap its creation in the using statement
Class A
for(int i=0; i < 350; i++)
{
MemoryStreamCreator.CreateMemStreamManaged();
Thread.Sleep(500);
}
Class B
public static void CreateMemStreamManaged()
{
using(MemoryStream memStream = new MemoryStream(100))
{
Console.WriteLine("Created Memory Stream " + i);
}
++i;
}
When I call this static method from my main calling class I had expected to see in my profiler objects of type MemoryStream being created and destroyed dynamically. However what i observed was 200 MemoryStream objects being created then destroyed, then a further 150 being created. Is this how the GC works?
Thanks
I have been working on a small C# project. As part of my testing I have been profiling the memory usage, and instances of classes created. I have tried to be careful to dispose of any objects that use Unmanaged code. As an example I have been using the MemoryStream object, however when I use it I wrap its creation in the using statement
Class A
for(int i=0; i < 350; i++)
{
MemoryStreamCreator.CreateMemStreamManaged();
Thread.Sleep(500);
}
Class B
public static void CreateMemStreamManaged()
{
using(MemoryStream memStream = new MemoryStream(100))
{
Console.WriteLine("Created Memory Stream " + i);
}
++i;
}
When I call this static method from my main calling class I had expected to see in my profiler objects of type MemoryStream being created and destroyed dynamically. However what i observed was 200 MemoryStream objects being created then destroyed, then a further 150 being created. Is this how the GC works?
Thanks