This project is read-only.

This feature is currently only supported in .NET 4.0 or higher. You can get via the MemoryDumper class all objects which are ready for finalization back into an object array to check if you did product too much garbage or where you did forget to call dispose.

/// <summary>
/// .NET 4.0 or above only. Get all finalizable objects which are ready for finalization and have no other object roots anymore.
/// </summary>
static void NotYetFinalizedObjects()
{
    using (var dumper = new MemoryDumper())
    {
        object[] finalizable = dumper.GetObjectsReadyForFinalization();
        Console.WriteLine("Currently {0} objects of types {1} are ready for finalization. Consider disposing them before.", 
                            finalizable.Length,
                            String.Join(",", finalizable.ToLookup( x=> x.GetType() )
                                                        .Select(   x=> x.Key.Name)) 
                            );
    }

}

Last edited Jun 23, 2012 at 12:00 AM by Alois, version 3

Comments

No comments yet.