FYI: A fix for memory leak when replacing a DataTable in a DataView

"Hewitt, Simon C. (Contractor)" <[email protected]> Tue, 12 Jun 2007 07:52:58 +0100
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <CF362B9DFA7D2544934516DFA1459AEC0147F627@BP1XEUEX709-C.bp1.ad.bp.com>
Here is a fix I found for a memory leak when replacing the DataTable a
DataView is wrapped around:

  // Do this
  FieldInfo fi =3D typeof(DataView).GetField("delayBeginEditList",
BindingFlags.Instance | BindingFlags.NonPublic);
  fi.SetValue(view, null);

  // before doing this
  View.Table =3D newTable;

If you don't clear the delayBeginEditList before assigning the new
DataTable, it retains a reference to a DataRow in the *old* DataTable,
which keeps the old DataTable in memory.

Cheers
Simon


=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
This list is hosted by DevelopMentor=AE  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com