Re:Ask HN: Why do langs with alleged “automatic memory manag...
by pmontra on Thursday July 18, 2019 @04:53PM
(#20473828)
Some languages (Python, Ruby, probably dozens of others) have constructs along these lines
with f = open("data.txt")
print f.readline()
The file is automatically closed at the end of the block. Those languages also have explicit open/close/seek calls to let the developer implement more complex cases.Btw, the os closes any open file when the program ends.
Re:Ask HN: Why do langs with alleged “automatic memory manag...
by ErotemeObelus on Thursday July 18, 2019 @05:16PM
(#20473993)
Yes, you're correct that os's have some kind of rudimentary reference counting for files, but it's very inchoate and not designed as the primary method of handling file references.
Re:Ask HN: Why do langs with alleged “automatic memory manag...
by brudgers on Thursday July 18, 2019 @11:12PM
(#20475905)
There's nothing wrong with Java, but there's been a lot of effort over the last two decades put into designing alternative languages for the JVM. Scala, Clojure, Groovy, and JRuby are examples (though none are primarily in the direction of automatic file handling).
And it's easy to determine when the use of the resource is complete: when there are no active pointers to the resource (the circular reference problem I don't think can happen with external resources like files).