No, there will be no memory leak in the code you show, assuming you use this term to indicate that objects are not garbage collected. The delegate for an anonymous event handler is a link that receives garbage collected for a long time with the rest of the objects created by the DataTable when it goes out of scope.
I created the following test setup to simulate what your code does:
static object DataSource; static void Main(string[] args) { Test1(); // clean up GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true); GC.WaitForPendingFinalizers(); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true); } static void Test1() { for (var i = 0; i < 1000; i++) { var dt = FetchChildren(i); DataSource = dt.DefaultView; dt.RowDeleted += (s, e) => { var table = (DataTable)s; Trace.WriteLine(String.Format("{0}:{1}:{2}", e.Action, e.Row.RowState, table)); }; // do work var dv = (DataView)DataSource; dv.Delete(5); } DataSource = null; } // create a useful datatable static DataTable FetchChildren(int parent) { var dt = new DataTable(); dt.Columns.Add("key", typeof(int)); dt.Columns.Add("guid", typeof(string)); for(var i=0; i<10; i++) { var row = dt.NewRow(); row[0] = parent; row[1] = Guid.NewGuid().ToString("N"); dt.Rows.Add(row); } return dt; }
When I run this using the Performance Explorer in Visual Studio in Instrumentaion mode and with Collect.Net Object's life information enabled, this is my result:

As you can see, all DataTable instances return to 0 when profiling ends, and this applies to all types that were created in this test.
If you keep the links, but at the end of the method you can get 1000 instances, as shown in this test file:
static void Test2() { for (var i = 0; i < 1000; i++) { var dt = FetchChildren(i); var local = DataSource;
So, until you keep reference to the instance you used earlier, you should be fine.
source share