Re: Re: Re: Re: my garbage collector sucks
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <008901c45e77$e887f580$0d01a8c0@MarkVaio> |
From: "Paul Prescod" > Explicitly closing files raises the exact same problems as explicitly > deleting memory. The only difference is that the average program deals > with fewer files than memory objects so the issue tends to be more > managable. But there is nothing magical about memory that says that it > is virtuous to let the implementation deal with it while it is naughty > to depend upon the implementation close files. There are many more ramifications of an open file than the simple ramification of an unclaimed memory space. There is for all intents and purposes a "magical" difference. IMHO, until finalization is fool-proof, it shouldn't be used on files. If you have code to open a file, then you should have code to close a file for good readability and reliability. Your example looked like it opened 10000 files because I saw no close. More complicated code than your example could have an open file get stuck in a reference cycle and never be closed. > I'm not pushing for reference counts: I'm just tired of illogical > arguments (not just here) against deterministic finalization. I repeated an argument that several "experts" made saying there was no difference between ref-counting and tracing. This argument was illogical and you corrected me. I do argue that you shouldn't use finalizers for several practical reasons, even in Python. These are practical reasons like implicitness, readability, functionality (even in Python you have to worry about cycles). If these arguments are illogical then feel free to correct me again. > By the way, you can get a subset of the benefits of deterministic > finalization if you implement a feature that scopes objects to their > containing functions as stack variables in C/C++ are scoped to their > containing functions. > > http://c2.com/cgi/wiki?DeterministicFinalization > > As long as you are careful to never pass these objects out of your > function you are okay... No thanks. I don't want to encourage the use of finalizers. If you want this kind of functionality use the explicit try/finally statements. That is what they are there for. If you want to come up with some new explicit finalizer equivalent that is scope-based, feel free.