"Joe" <jb*******@noem ail.noemail> a écrit dans le message de news:
Oz************* *@TK2MSFTNGP12. phx.gbl...
|I might be overworked so please excuse this stupid question...
|
| Say I do the following:
|
| DataTable table = new DataTable();
|
| myDataAdaptor.F ill(table);
|
| dataGrid1.DataS ource = table;
|
| table = null;
|
| Why does dataGrid1.DataS ource still point to a table?
|
| How can I set an object to null and have all references to that object now
| be null?
You can't. You can only set references to objects to null.
If you know C tthen you would remember that object references hold the
addresses of objects and you would have to dereference that pointer to get
at the object. You could "delete" the object and then the pointer would be
invalid and would have to be nulled to avoid AVs.
In C#, all objects are garbage collected, you can't "delete" them. When the
last reference to a given object falls out of scope, the object is liable to
collection. You can certainly null as many references as you can find, but
the object will remain alive as long as *any* reference still holds that
object.
In your example, the DataGris's DataSource is holding a reference to the
table, so even though you null the original reference, 'table', the object
that 'table' was pointing to is kept alive by the DataSource property.
Why would you want to null a property to which you have only just assigned a
valid object ?
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer