|
![](/i/fill.gif) |
Mike Raiford wrote:
> Darren New wrote:
>
>>
>> The destructor will close the file when the GC collects the object,
>> but that might be several seconds later. And it might not run if you
>> exit the program before the GC runs, but that's true of C++ also. So
>> it's not quite as nicely deterministic, but it still happens eventually.
>>
>
> C# has the same issue. You can sort of work around it with the using
> statement, which will call Dispose on an IDisposable object, which, in
> turn, closes the file.
Yep. Of course, it's really not a problem in a system where the kernel
participates in the GC, like Singularity does.
And, really, memory is a huge percentage of the resources you manage, so
the small bit of "real" resources you have to handle manually is usually
not much of a problem. Indeed, only once did I have code sufficiently
convoluted and error-prone that I had a resource leak of this type in
Tcl. And even then, it's because I wrote the code poorly and instead of
(say) wrapping the allocation and use in a procedure call, I tried to
handle it all inline.
--
Darren New / San Diego, CA, USA (PST)
Post a reply to this message
|
![](/i/fill.gif) |