Destructor called while object is still alive

Steven Schveighoffer schveiguy at gmail.com
Sun Oct 25 15:50:36 UTC 2020


On 10/25/20 5:17 AM, Kagamin wrote:
> On Saturday, 24 October 2020 at 11:56:54 UTC, Steven Schveighoffer wrote:
>> I wrote a program long ago that used classes to manage open files. I 
>> never worried about cleaning up the file handles, and it worked fine.
> 
> Programs that don't care to close file handles are the reason why people 
> believe that windows can't run for more than a week without restarts, a 
> file handle is small for the program, but kernel allocates a fairly big 
> structure about 4kb; when the program opens a million handles, it 
> consumes 4gb of kernel memory, when a non-technical user sees this 
> system wide memory shortage, he concludes time has come to restart the 
> system. Particularly Nvidia user service was guilty of this and given 
> that it's installed on most machines, you get the corresponding result.

This was not on Windows, and the GC cleaned up the file handles as it 
ran. They weren't left open constantly.

But even if you have synchronous management of files, having a 
destructor clean up a file that obviously isn't used any more isn't a 
bad thing.

-Steve


More information about the Digitalmars-d mailing list