Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'll have to disagree here.

Leaking resources in Rust is pretty trivial: create an Rc cycle with internal mutability. By contrast, in languages with a GC, cycles will be properly collected.

And there is nothing preventing GC languages from tying their non-memory resources to the lifetime of a value like Rust. See Python files, which are closed when the file handle is collected (ie. when all variables holding it go out of scope), and if that's not explicit enough, there's the "with" keyword to explicitly introduce a scope at the end of which the file is closed.




> Leaking resources in Rust is pretty trivial: create an Rc cycle with internal mutability.

It's trivial to do on purpose, but difficult to do accidentally.


> See Python files, which are closed when the file handle is collected (ie. when all variables holding it go out of scope)

That's a CPython implementation detail.

https://docs.python.org/3/reference/datamodel.html

> Do not depend on immediate finalization of objects when they become unreachable (so you should always close files explicitly).


In Rust, the default behavior when using resources like any other type is correct. You have to introduce a specific type to leak them.

In Python, you need to handle resources differently and introduce a language feature to not leak them.

That's the difference you're pointing out.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: