Here's where .NET starts to do my head in. Consider the following scenario:
- I have a DataTableobject, containing a number ofDataRowobjects
- I add some of the DataRowobjects to an Array
- I call Disposeon theDataTable.
What guarantee do I have that calling Dispose on the DataTable won't compromise the DataRow objects (which, by reference, would affect those added to the Array)?
MS documentation is zero help in this case.
EDIT: So far folks have missed the point entirely. IDisposable objects are meant to be disposed of as soon as possible. My code is going to be creating thousands of DataTable objects during a typical day. No way am I leaving those un-disposed if they implement IDispoable.
BUT, I need the handful of DataRow objects to stay alive because that's what my 3rd-party binary (which I have no control over) expects. And I need them to stay alive for significantly longer than the DataTable objects.
All I need is authoritative information that describes what Dispose on a DataTable actually does. Looks like said information does not exist, which is why I'm asking here for help. Someone may have a reference, or documentation I have overlooked, that answers my need.
EDIT 2: I have tested as Blam suggested, including adding GC.Collect + a bonus GC.WaitForPendingFinalizers + one more GC.Collect after disposing the DataTable. The DataRows appear to be fine, still alive and accessible. That's positive, but alas not authoritative enough to include in production code :-(
 
     
     
    