garbage collection of open resources
From: Mark Broadbent (no-spam-please_at_no-spam-please.com)
Date: 04/22/04
- Next message: David Browne: "Re: try/finally with data access code"
- Previous message: Bruno Jouhier [MVP]: "Re: try/finally with data access code"
- Next in thread: John Wood: "Re: garbage collection of open resources"
- Reply: John Wood: "Re: garbage collection of open resources"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 22 Apr 2004 17:04:36 +0100
Everything I have read suggests that if I open files or database connections
or the like, that I should explicitly close those said resources before
making the object subject to GC. This is obviously good programming
technique.
However what happens if this practice is not followed. e.g.
that I have a base object that creates an instance of a filestream and for
arguements sake an instance of a oledb connection.
Both sub objects are opened (one to a file and one to a db) and used to
read/ write data.
Say for instance that I implement the IDisposible interface for the parent
class definition (that instanciates both objects) and within the Dispose()
method I set both object variable references to null (without closing them).
I am under the impression that they will be made available to the GC.
My question is - could data corruption occur to any open data sources that
have been made available to garbage collection OR does (as I suspect) it
simply means that those open resources (open files) will simply be locked
out until the GC destroys them?
Obviously I know that there are several reasons for closing the resources
but I would like to know that corruption is not one of them.
-- Br, Mark Broadbent mcdba , mcse+i =============
- Next message: David Browne: "Re: try/finally with data access code"
- Previous message: Bruno Jouhier [MVP]: "Re: try/finally with data access code"
- Next in thread: John Wood: "Re: garbage collection of open resources"
- Reply: John Wood: "Re: garbage collection of open resources"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|