POV-Ray : Newsgroups : povray.off-topic : C++ questions : Re: C++ questions Server Time
7 Sep 2024 11:21:00 EDT (-0400)
  Re: C++ questions  
From: Darren New
Date: 26 Sep 2008 13:09:15
Message: <48dd173b$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.