1- // Copyright (c) 2010-2014 SharpDX - Alexandre Mutel
1+ // Copyright (c) 2010-2018 SharpDX - Alexandre Mutel
22//
33// Permission is hereby granted, free of charge, to any person obtaining a copy
44// of this software and associated documentation files (the "Software"), to deal
@@ -42,22 +42,25 @@ public int Count
4242 /// <summary>
4343 /// Disposes all object collected by this class and clear the list. The collector can still be used for collecting.
4444 /// </summary>
45+ /// <param name="disposeManagedResources">If true, managed resources should be
46+ /// disposed of in addition to unmanaged resources.</param>
4547 /// <remarks>
4648 /// To completely dispose this instance and avoid further dispose, use <see cref="Dispose"/> method instead.
4749 /// </remarks>
48- public void DisposeAndClear ( )
50+ public void DisposeAndClear ( bool disposeManagedResources = true )
4951 {
5052 if ( disposables == null )
51- {
5253 return ;
53- }
5454
5555 for ( int i = disposables . Count - 1 ; i >= 0 ; i -- )
5656 {
5757 var valueToDispose = disposables [ i ] ;
58- if ( valueToDispose is IDisposable )
58+ if ( valueToDispose is IDisposable disposable )
5959 {
60- ( ( IDisposable ) valueToDispose ) . Dispose ( ) ;
60+ if ( disposeManagedResources )
61+ {
62+ disposable . Dispose ( ) ;
63+ }
6164 }
6265 else
6366 {
@@ -76,7 +79,7 @@ public void DisposeAndClear()
7679 /// disposed of in addition to unmanaged resources.</param>
7780 protected override void Dispose ( bool disposeManagedResources )
7881 {
79- DisposeAndClear ( ) ;
82+ DisposeAndClear ( disposeManagedResources ) ;
8083 disposables = null ;
8184 }
8285
0 commit comments