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
}
}
MemAssertion.NoInstances(Type[], bool)
-
- Posts: 3
- Joined: Wed Feb 01, 2006 10:43 pm
-
- Posts: 1029
- Joined: Wed Mar 02, 2005 7:53 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.
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
Andreas Suurkuusk
SciTech Software AB
Who is online
Users browsing this forum: No registered users and 1 guest