none
Cleaning up a DataSet RRS feed

  • Question

  • I'm trying to garbage collect a DataSet. I have created a sub class of DataSet with a destrcutor to monitor garbage collection. The DataSet is created within a method. When the DataSet goes out of scope, it should have been garbage collected. But the desctructor is never called. Not even if I force garbage collection with GC.Collect() and GC.WaitForPendingFinalizes(). When is a DataSet garbage collected?

     

    A related question: How are string referenced in a DataRow? What I mean is if I have a DataRow with a string type column. I then retrieve the string and store the value in a variable. The DataSet to which the DataRow belongs to is dereferenced. Will the string variable keep the DataSet from beeing garbage collected? Or is it a copy of the value in the DataRow?

     

    Regards

    Bjørn Terje Svennes

    Wednesday, June 6, 2007 10:08 AM

Answers

  • How does your destructor look like? Once an object is to be garbage collected it can not do certain things and depending on how your destructor looks like it might actually throw an exception and fail in reporting its been collected.

     

    Strings are immutable and it means a reference to a string is never referencing another string, just the same string data. A shared string reference should never block an object referencing it to be collected by the garbage collector.

    Sunday, June 10, 2007 4:33 AM

All replies

  • How does your destructor look like? Once an object is to be garbage collected it can not do certain things and depending on how your destructor looks like it might actually throw an exception and fail in reporting its been collected.

     

    Strings are immutable and it means a reference to a string is never referencing another string, just the same string data. A shared string reference should never block an object referencing it to be collected by the garbage collector.

    Sunday, June 10, 2007 4:33 AM
  • I found a way to make the system call the DataTable's destructor. It didn't work with DataSet. But I reached the same conclusion as you: Strings don't obstruct the DataTable from beeing garbage collected.

     

    Thank you for answering.

    Thursday, June 21, 2007 7:51 AM