After having used it to diagnose a memory leak, I want to use it as part of our automated build process to detect and notify us of future potential memory leaks. I've created a small test app that creates a baseline snapshot, creates some objects, asserts that those objects do not exist (to test assertion failures), and then takes a final snapshot.
I'd like my code to do 2 things when an assertion fails:
1. Log the failed assertion
2. If I later open the generated profiler session in the UI, have it show the "Potential memory leak" warning
I've been able to easily get either #1 or #2 in isolation, but have noticed something odd when I try to get both #1 and #2 using a single assertion.
If I do anything to evaluate the bool value returned from a MemAssertion.NoNewInstances method call, #2 does not happen (i.e., the UI doesn't show the "Potential memory leak" warning when I open the generated session file).
I've tried both:
Code: Select all
if (!MemAssertion.NoNewInstances(...))
File.Create("houston.txt"); //We will do logging here instead
Code: Select all
bool assertionResult = MemAssertion.NoNewInstances(...);
if (!assertionResult)
File.Create("houston.txt"); //We will do logging here instead
If I make a "naked" assertion (i.e., don't check or save the return value), I do get the "Potential memory leak" warning in the generated session (good), but then I have to make the assertion twice (bad) in order to do something conditioned on whether the assertion failed. As in:
Code: Select all
MemAssertion.NoNewInstances(...);
if (!MemAssertion.NoNewInstances(...)
File.Create("houston.txt"); //We will do logging here instead