3 ms·
> And for application-level programming, why would you chose a language without a garbage-collector? Because your code uses some finite resources other than me
by tbrownaw 16y ago
> And for application-level programming, why would you chose a language without a garbage-collector?
Because your code uses some finite resources other than memory, and you don't want the ability to forget to release said resources when you're done with them and they go out of scope.
- eru 16y agoWhy should memory management related to managing other resources. Anyway, you might be interested in The Haskell Disciplined Disciple Compiler (http://www.haskell.org/haskellwiki/DDC http://www.haskell.org/haskellwiki/DDC) which lets you statically encode resource management rules. (And of course spots garbage collection for memory.)
- tbrownaw 16y agoYour objects contain/use various resources, such as memory, file descriptors, mutexes, etc. The way to reclaim any of these is to destroy the object, which lets you reclaim all of them. So memory management is very much tied to other resource management, since they both involve the same thing (deciding when to destroy objects you no longer need). Unfortunately not all resources can be collected equally lazily, so memory-centric GC schemes that ignore the requirements of other resources tend to get in the way (and make you do using(){...} or try/finally to make sure your files are closed, instead of allowing for RAII).
- eru 16y ago> The way to reclaim any of these is to destroy the object, which lets you reclaim all of them. I asked why one should mix management of resources, and you answer that one should mix management of resources. But I still don't know why?
- tbrownaw 16y agoIt's more that how the hell do you unmix them (any why would you bother, anyway)?
- eru 16y agoHow to unmix: Just e.g. close your files explicitly, but let the memory of the data structures that represent your files be garbage collected normally. For patterns of usage similar to RAII, Common Lisp uses unwind-protect. I already mentioned Disciplined Disciple Compiler that extends Haskell to give static guarantees for following certain rules for resource management. Why would you bother: RAII only covers some cases for resource management, and most garbage collectors can take an arbitrary long time to collect an object that's no longer reachable. Which is fine for memory, because memory is fungible, but the attached resources, say mutexen, are not necessarily fungible.