Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

Commit b8de7a7

Browse files
authored
Merge pull request #915 from jclin/CustomLogging
Allow custom memory leak logging for client apps
2 parents e17def2 + e2865ce commit b8de7a7

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Source/SharpDX/ComObject.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ namespace SharpDX
2828
/// </summary>
2929
public class ComObject : CppObject, IUnknown
3030
{
31+
/// <summary>
32+
/// Logs a warning of a possible memory leak when <see cref="Configuration.EnableObjectTracking" /> is enabled.
33+
/// Default uses <see cref="System.Diagnostics.Debug"/>.
34+
/// </summary>
35+
public static Action<string> LogMemoryLeakWarning = (warning) => System.Diagnostics.Debug.WriteLine(warning);
36+
3137
/// <summary>
3238
/// Initializes a new instance of the <see cref="ComObject"/> class.
3339
/// </summary>
@@ -288,7 +294,7 @@ protected unsafe override void Dispose(bool disposing)
288294
if(!Configuration.EnableReleaseOnFinalizer)
289295
{
290296
var objectReference = ObjectTracker.Find(this);
291-
System.Diagnostics.Debug.WriteLine(string.Format("Warning: Live ComObject [0x{0:X}], potential memory leak: {1}", NativePointer.ToInt64(), objectReference));
297+
LogMemoryLeakWarning?.Invoke(string.Format("Warning: Live ComObject [0x{0:X}], potential memory leak: {1}", NativePointer.ToInt64(), objectReference));
292298
}
293299
}
294300

0 commit comments

Comments
 (0)