Page 1 of 1

MemAssertion.NoInstances(Type[], bool)

Posted: Wed Mar 15, 2006 10:05 pm
by scot.prichard@med.ge.com
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
}
}

Posted: Thu Mar 16, 2006 1:17 pm
by Andreas Suurkuusk
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.