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.", 
                            String.Join(",", finalizable.ToLookup( x=> x.GetType() )
                                                        .Select(   x=> x.Key.Name)) 


Last edited Jun 22, 2012 at 11:00 PM by Alois, version 3


No comments yet.