MemAssertion.NoNewInstances(), NoNewInstancesExcept(Type)

Use this forum to discuss and/or suggest future improvements of .NET Memory Profiler and to report bugs.
Post Reply
scot.prichard@med.ge.com
Posts: 3
Joined: Wed Feb 01, 2006 10:43 pm

MemAssertion.NoNewInstances(), NoNewInstancesExcept(Type)

Post by scot.prichard@med.ge.com » Wed Mar 15, 2006 10:25 pm

Why does this code Assert?

class Test { }

class Program
{
static void Main(string[] args)
{
MemProfiler.FullSnapShot();
MemProfiler.FullSnapShot();
MemAssertion.NoNewInstances();
MemProfiler.FullSnapShot();
using (MemAssertion.BeginAssertions())
{
MemAssertion.NoNewInstances();
}

Test test = new Test();
MemAssertion.NoNewInstancesExcept(typeof(Test));
}
}

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

Post by Andreas Suurkuusk » Thu Mar 16, 2006 1:11 pm

Using MemAssertion.NoNewInstances and MemAssertion.NoNewInstancesExcept require that you perform the assertions in an "assertions session", otherwise it is very likely that memory leaks will be falsely detected. So in your case, the first and the third assertion will fail, since short-lived instances will be created during the assertion itself. However, the second assertion should not fail.

It appears that assertions didn't work when using a MemProfiler.FullSnapshot as comparison snapshot. This was a bug in the profiler which has now been fixed and an updated version of the profiler has been released. You can download this version (v2.6.82) 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 2 guests