D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4490 - File ref counting broken for anonymous File structs
Summary: File ref counting broken for anonymous File structs
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other All
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on: 3516
Blocks:
  Show dependency treegraph
 
Reported: 2010-07-20 13:24 UTC by David Simcha
Modified: 2011-08-12 20:38 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2010-07-20 13:24:51 UTC
The following runs out of file handles on both Windows and Linux:

import std.stdio;

void main() {
    // Assumes you have a file called "foo.txt" laying around.  If you don't,
    // create one.
    while(1) {
        File("foo.txt");
    }
}

The following while loop body also does:

auto lines = File("foo.txt").byLine();

The following does not:

auto handle = File("foo.txt");

Marking as major because it silently breaks code in subtle ways.  I wrote several small programs that relied on reference counting to free the file handle, which seemed to work fine until one day I made them use a lot more file handles than they usually do.
Comment 1 David Simcha 2010-07-25 10:12:38 UTC
Apparently, this is caused by bug 3516, rather than being a bug in Phobos per se.
Comment 2 David Simcha 2011-08-12 20:38:43 UTC
Resolved by fixing temporary destruction.