MemAssertion.NoInstances(Type[], bool)

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.NoInstances(Type[], bool)

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

Why doesn't this code assert?

class Parent { }
class Child : Parent { }

class Program
{
static void Main(string[] args)
{
Type[] types = new Type[] { typeof(Parent) };
MemProfiler.FastSnapShot();

MemAssertion.NoInstances(types, true);
Child child = new Child();
MemAssertion.NoInstances(types, true); // fails to assert
}
}

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

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

In a debug build the assertion should probably fail, but since the child variable is not used after the assertion, it is possible that the Child instance becomes collected before the assertion. In a release build the scopes of variables are smaller, and the assertion will never fail.

However, the reason that the assertion doesn't fail is that the includeSubclasses argument was ignored by the NoInstances methods that accept a Type[] array. This 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: Google [Bot] and 3 guests