Re: garbage collection
From: Bijoy Naick (b_naick_at_yahoo.ca)
Date: 12/14/04
- Next message: ST: "Re: Parser error"
- Previous message: Kumar Reddi: "Re: Very simple viewstate question"
- In reply to: Kumar Reddi: "Re: garbage collection"
- Next in thread: Kumar Reddi: "Re: garbage collection"
- Reply: Kumar Reddi: "Re: garbage collection"
- Reply: Scott Allen: "Re: garbage collection"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 14 Dec 2004 15:15:23 -0500
Understood.. so what happens in the following case..
Assume that I have a custom class - call it Events. One of the methods of
this class is GetEvents defined/implemented as follows:
public function GetEvents(startDate, endDate) as sqlDataReader
Dim myReader As SqlDataReader
Dim oConn As SqlConnection
oConn.Open()
sql = "select * from events in date range"
myReader = oConn.ExecuteReader(sql)
oConn.Close()
return myReader
end function
If an aspx page creates an instance of the Events class and calls the
GetEvents method, it will get a reader back.. How can I close the reader
defined in the GetEvents method?
BTW: I took a look at the code in the Application Block provided by Msft
called SqlHelper. Their code doesnt close the reader either..
Bijoy
"Kumar Reddi" <KumarReddi@REMOVETHIS.gmail.com> wrote in message
news:ORFESfh4EHA.4028@TK2MSFTNGP15.phx.gbl...
>
> First of all, with datareaders, if you do not close the reader after the
> usage, you can not reuse the connection on which it opened. This is not a
> garbage collection issue, its a logical error. Garbage collection cleans
the
> resources for you, by doing automatic memory deallocation, but it doesnt
> close the datareader for you. Thats your job. Also, If your application
> doesnt allow database connection pooling, you need to dispose your
database
> connection. But, your application seems to be using the connection
pooling,
> so you do not have to worry. By the way, the reason you need to call
dispose
> on database connection is, it is unmanaged object. GC can not clean the
> unmanaged resources for you
> --
> Kumar Reddi
> http://kumarreddi.blogspot.com
>
> "Bijoy Naick" <b_naick@yahoo.ca> wrote in message
> news:uTRytYh4EHA.1564@TK2MSFTNGP09.phx.gbl...
> > Just wondering if anyone has experienced any issues with garbage
> collection
> > in .net. We developed an application using VB .NET; many of the pages
made
> > db calls.
> >
> > One of the developers forgot to close the connection(s) and DataReader
> > objects. We found that once the site recieved a large number of hits,
the
> > server died on us and memory usage was ridiculously high. Since that,
> we've
> > closed all the connections and datareaders and the app works great..
> >
> > Should the .NET GC not have managed all of this for us?
> >
> > BTW: I know its good coding practice to close everything you open.. but
> just
> > wondering IF GC does this or not..
> >
> > Bijoy
> >
> >
>
>
- Next message: ST: "Re: Parser error"
- Previous message: Kumar Reddi: "Re: Very simple viewstate question"
- In reply to: Kumar Reddi: "Re: garbage collection"
- Next in thread: Kumar Reddi: "Re: garbage collection"
- Reply: Kumar Reddi: "Re: garbage collection"
- Reply: Scott Allen: "Re: garbage collection"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|