garbage collection of open resources

From: Mark Broadbent (no-spam-please_at_no-spam-please.com)
Date: 04/22/04


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
=============


Relevant Pages

  • Re: garbage collection of open resources
    ... > Eventually you might run out of resources. ... > The GC does dispose of all objects eventually, and even if you set the ... >>Everything I have read suggests that if I open files or database ... >>Obviously I know that there are several reasons for closing the resources ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Pythons "only one way to do it" philosophy isnt good?
    ... I don't rely on the refcounter for resources that ABSOLUTELY, ... Open files, for instance, rarely do. ... I actually want access to them in the traceback for debugging ... If a procedure catches an exception but isn't going to return ...
    (comp.lang.python)
  • Re: maximum number of threads
    ... Gabriel Genellina wrote: ... as you can't have 10000 open files at once. ... resources are not infinite. ...
    (comp.lang.python)
  • Re: maximum number of threads
    ... Gabriel Genellina wrote: ... as you can't have 10000 open files at once. ... resources are not infinite. ...
    (comp.lang.python)
  • Re: Help: Too many files open
    ... the current number of open files. ... Most all Java IDE's will let you do debugging at the instruction level. ... For Database connections depends on how you are opening the connection. ... I did a quick Google for the error you are getting and came up with a lot of hits. ...
    (comp.lang.java)