Hello
I have a class that implements IDisposable with the following code.
/// <summary> /// This should be called to free up system resources when the object is finished with /// </summary> public void Dispose()
{
// Call the clean up routineCleanUp(
true); // Stop the finializer calling GC.SuppressFinalize(this);}
#endregion
/// <summary> /// Dispose of the managed resources /// </summary> /// <param name="disposing"></param> private void CleanUp(bool disposing){
// Check we haven't already been disposed of if (!m_disposed){
if (disposing){
// Clean up the managed resources}
// Always clean up the unmanaged resources}
// Set the flag to show the object has been disposedm_disposed =
true;}
/// <summary> /// Finalizer method called on garbage collection /// </summary>~Memento()
{
// Clean up specifying that it is not being disposed rather finalizedCleanUp(
false);}
I have written some unit tests and when checking the coverage I get the Finalize method being called just once when the tests complete. However as far as I can see I dispose of the object every time it is created or used.
I obviously want to dispose every time the object is used but I cannot tell from the call stack what is leaving the object behind as it simple contains the finalize method.
Is there anyway of working out what is happening