Created
April 3, 2016 19:23
-
-
Save NVentimiglia/b08d6c92be0d2015871ce9fd23aeed09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class LeakTracker | |
{ | |
static List<WeakReference> _tracker = new List<WeakReference>(); | |
/// <summary> | |
/// should be called only at object construction/instantiation | |
/// </summary> | |
public static void Add(object objToTrack) | |
{ | |
Prune(); | |
_tracker.Add(new WeakReference(objToTrack)); | |
} | |
public static void Prune() | |
{ | |
_tracker = _tracker.Where(o => o.IsAlive).ToList(); | |
} | |
public static string Dump() | |
{ | |
Prune(); | |
return string.Join("\r\n", _tracker.Select(o => o.Target).Where(o => o != null).Select(o => o.GetType().ToString())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment