3 ms·
Not exactly a systems language, but Python has deterministic destruction (due to the use of reference counting) of non-cyclic data structures. Edit: Oh, and if
by manwe150 7y ago
Not exactly a systems language, but Python has deterministic destruction (due to the use of reference counting) of non-cyclic data structures.
Edit: Oh, and if you don’t think that’s enough, note that Rust doesn’t guarantee destruction to ever occur in that case (“considered safe”):
https://doc.rust-lang.org/book/ch15-06-reference-cycles.html https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
- dpc_pw 7y agoOh, interesting. But from what I read it's only an implementation detail of CPython? With `with`I can't eg. pass an open file to another function to eg. be closed there etc. Example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=660bf12eee1338d4b05f747b2ba99ed6 https://play.rust-lang.org/?version=stable&mode=debug&editio... closing `File` will happen at the end of `foo` or `foo2`.
- manwe150 7y agoThat's probably a tricky question, since CPython is also essentially the spec. PyPy talks a bit about this: http://doc.pypy.org/en/latest/cpython_differences.html#differences-related-to-garbage-collection-strategies http://doc.pypy.org/en/latest/cpython_differences.html#diffe... That's true, since Python has reflection it can't easily optimize that case, whereas that's a powerful benefit of having a linear type system for tracking ownership like Swift or Rust. But early freeing (which Rust has and Python does not) is slightly different from deterministic freeing (which both have) is slightly different from guaranteed freeing (which CPython has and Rust does not).
- kevinmgranger 7y ago> Python has deterministic destruction Not quite. https://docs.python.org/3/reference/datamodel.html#object.__del__ https://docs.python.org/3/reference/datamodel.html#object.__... > It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits.