When is reader internals garbagecollected?

  • Thread starter Thread starter me
  • Start date Start date
M

me

With ASP.OLD when I threw away a refence to a recordset
but still had a live refence to some datafield inside the
recordset then ASP would never the less garbagecollect the
recordset and the datafields, which sometimes resultet in
me trying to use variables that were null if I hadnt remembered
to make a copy of the field instead of just referencing it.

With ADO.NET do I have to copy referencetypes as well if I
want to use the data after the reader is closed()?
 
me said:
With ASP.OLD when I threw away a refence to a recordset
but still had a live refence to some datafield inside the
recordset then ASP would never the less garbagecollect the
recordset and the datafields, which sometimes resultet in
me trying to use variables that were null if I hadnt remembered
to make a copy of the field instead of just referencing it.

With ADO.NET do I have to copy referencetypes as well if I
want to use the data after the reader is closed()?

Each individual field won't have a reference to the table, no - a
string can't have a reference to a table, for instance.

If you are keeping whole *rows* of the table, I'd imagine (although I
haven't checked) that the row may well have a reference to the table it
is part of.
 
(e-mail address removed) (me) writes
With ASP.OLD when I threw away a refence to a recordse
but still had a live refence to some datafield inside th
recordset then ASP would never the less garbagecollect th
recordset and the datafields, which sometimes resultet in
me trying to use variables that were null if I hadnt remembered
to make a copy of the field instead of just referencing it
want to use the data after the reader is closed()

There's mention of this on cbrumme's weblo

http://blogs.msdn.com/cbrumme/archive/2004/02/02/66219.asp

in the section on "ADO's Threading Model"

"Instead, the ADO team solved the problem for managed code with a ver
elegant technique. (I invented it, so of course I think it wa
elegant). They opened up the assembly that was created b
TlbImping ADO. Then they added managed references from the RCW
of the field values to the RCWs of their owning rows. These manage
references are completely visible to the garbage collector. Now th
GC knows that if the field values are reachable then the row value
must also be reachable. Problem solved."
 
Do you agree that the translation of that is that i dont have to copy
fields inside the reader, cos the gc knows about them?
 
Just to clarify: in 1.0/1.1, the values we return from the reader do not
have a reference back to the reader object itself. So you'll never end up in
a situation where by holding a reference to a value you obtained from the
reader you'll be keeping the reader itself alive.

Note that in any case you should not rely on scoping and GC collection to
free up readers. Calling Close() or Dispose() is safer and clearer.

--
Pablo Castro
Program Manager - ADO.NET Team
Microsoft Corp.

This posting is provided "AS IS" with no warranties, and confers no rights.
 
ok tnx all for replies. I think this should have more prominent
documentation.
The 3 books I have read on asp.net/ado.net mention nothing of this, although
its completely opposite of how asp.old/ado/jscript behaved.
 
Back
Top