VirtualMemory discrepancy?

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
RebelGecko
Posts: 1
Joined: Tue Feb 26, 2008 9:05 pm

VirtualMemory discrepancy?

Post by RebelGecko » Wed Feb 27, 2008 4:00 pm

This is my first post, so I feel the need to gush over the tool you have created...it is awesome and every developer should have it. Thanks for your vision and efforts!

Now, my question: using 3.1.271, it seems that the VirtualMemory tracker does not notice deallocations. Try this simple program:

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace thredd
{
  class Program
  {
    static ReaderWriterLock _sync = new ReaderWriterLock();
    static AutoResetEvent _ok = new AutoResetEvent(false);

    static void Main(string[] args)
    {
      Console.WriteLine("press any key to begin");
      Console.ReadKey();

      _sync.AcquireReaderLock(Timeout.Infinite);
      for (int i = 0; i < 1000; i++)
      {
        new Thread(thread).Start();
        _ok.WaitOne();
        Console.Write(i);
        Console.Write("\r");
      }
      _sync.ReleaseReaderLock();

      _sync.AcquireWriterLock(Timeout.Infinite);
      _sync.ReleaseWriterLock();
      _ok.Close();
      _ok = null;
      _sync = null;

      Console.WriteLine("done");
      GC.Collect();
      Console.ReadKey();
    }

    static void thread()
    {
      _sync.AcquireReaderLock(Timeout.Infinite);
      _ok.Set();
      Thread.Sleep(5000);
      _sync.ReleaseReaderLock();
    }
  }
}
Once this program makes it past the GC.Collect call, perfmon shows the majority of the Virtual Bytes have been deallocated. However, memprofiler still shows over 1GB allocated.

Is this a bug or am I reading my indicators wrong?

TIA

Andreas Suurkuusk
Posts: 1029
Joined: Wed Mar 02, 2005 7:53 pm

Post by Andreas Suurkuusk » Wed Feb 27, 2008 8:15 pm

Thank you very much for the information. It seems like you have encountered a bug in the unmanaged resources tracker. As mentioned in the documentation, the "unmanaged nature" of the resource tracking introduces a risk of missing resource creations or releases. In this case the profiler failed to track when thread stack memory was released. We have now fixed this problem, and we will soon release a maintenance build including this fix.

Thank you again, and I'm glad that you like our program.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Andreas Suurkuusk
Posts: 1029
Joined: Wed Mar 02, 2005 7:53 pm

Post by Andreas Suurkuusk » Thu Mar 06, 2008 2:00 pm

We have now released a maintenance build of .NET Memory Profiler 3.1. This release contains the fix for the problem with the detection of released thread stack memory. It can be download from http://memprofiler.com/download.aspx.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests