The DataTable uses a couple of internal classes to maintain its indexes. When you call NewRow(), the row is passed to an instance of RecordManager, which is basically a primary key for the table (regardless of any key column you specify). Even if you don't add the DataRow to the table's Rows collection, the RecordManager still tracks it. The only way I know of to clear that reference is to call Clear() on the DataTable. This resets its indexes and clears out all the DataRow references.
Jim > -----Original Message----- > From: MSTSE Developer [mailto:[EMAIL PROTECTED]] > Sent: 26 April 2002 09:10 > To: [EMAIL PROTECTED] > Subject: [DOTNET] memory leak when creating datarow > > > i'm having a problem with destroying datarow objects. The methode > DataTable.NewRow() returns an empty row for the table but does not > insert the row into the table. when the row is member of the > table there > is no problem at deleting the row but my problem is to destroy the row > without inserting it into the table. is the row maybe part of another > collection in the table than the "Rows" collection which prevent that > the garbage collector is collecting the row. > > public class RowSample > { > DataRow m_DataRow = null; > > public RowSample(DataTable dt) > { > m_DataRow = dt.NewRow(); > > // without these line there is a memory leak > dt.Rows.Add(m_DataRow); > } > > ~RowSample() > { > m_DataRow.Delete(); > > m_DataRow = null; > } > } > > You can read messages from the DOTNET archive, unsubscribe > from DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.