6 ms·
Hi, I wrote the course :-) Yes, this is a real thing — Android has had support for Rust in the Android Platform for a few years now. Most recently, we shipped s
by mrtngslr 4y ago
Hi, I wrote the course :-) Yes, this is a real thing — Android has had support for Rust in the Android Platform for a few years now. Most recently, we shipped support for DNS-over-HTTP/3: https://security.googleblog.com/2022/07/dns-over-http3-in-android.html https://security.googleblog.com/2022/07/dns-over-http3-in-an...
We put out the course to make it easy for even more people to onboard with Rust.
- lillecarl 4y agoRust does not guarantee that there are no memory leaks, you can have things reference eachother and therefore never count to 0. This is why weak pointers exist in rust.
- pkolaczk 4y agoIt does not guarantee, but it is actually quite hard to cause a memory leak by accident, because at the same time Rust makes creating cycles hard.
- mrtngslr 4y agoI actually haven't tried this... do you know off the top of your head what it takes to make a cycle with Rc? It should not be possible with normal borrows (and safe Rust) since they're statically checked to be acyclic.
- britneybitch 4y agoYou could store a `RefCell<Option<T>>` in an `Rc` and set it to `Some(rc)` after creation. Or you could use the recently-stabilized `new_cyclic` method: https://doc.rust-lang.org/std/rc/struct.Rc.html#method.new_cyclic https://doc.rust-lang.org/std/rc/struct.Rc.html#method.new_c...
- bitexploder 4y agoAnd when using C libraries / FFI, there are a lot of tricky things going in, it is much easier to leak in unsafe land.
- jamincan 4y agoThe Rust Book has an example: https://doc.rust-lang.org/book/ch15-06-reference-cycles.html https://doc.rust-lang.org/book/ch15-06-reference-cycles.html Of course, leaking memory is as easy as using `Box::leak`, although that's probably never going to happen accidentally.
- junon 4y agoYou're incorrect, sorry. It's very easy to creat cycles in inner-mutable data structures (e.g. Rc).
- mrtngslr 4y agoRight, this is a problem with reference counted data structures in general. You're correct that Rust doesn't try to solve this particular problem. Put differently, the borrow checker won't allow you to create a cycle of refrences (the & kind). But you can do it with library types such as Rc.
- fulafel 4y agoIt's a property of basic RC but real-world RC based GC systems can often collect reference cycles. For example Python and PHP do this. (I'm sure you knew this, just adding to the discussion)
- eloff 4y agoRust doesn’t though. But it does make it much harder to leak memory than C. You need to create a cycle between reference counted objects versus just forget to free something. Not that it matters as much as people think. Memory leaks aren’t a correctness problem. You typically want to restart a program or service regularly anyway to deal with memory fragmentation. You also frequently have a watchdog like systemd to restart your program if it crashes. Heroku restarts your whole dyno once a day. This means in practice that programs with slow memory leaks tend to work just fine (there are plenty of them in the wild.)
- fulafel 4y agoInteresting view that memory leaks aren't correctness problems. But I would require more convincing to agree. It's true that memory leaks can be small enough that they don't become problems in the end-to-end behaviour of the system in regular use. But a lot of bugs are like that. For example many memory safety bugs.
- masklinn 4y ago> Interesting view that memory leaks aren't correctness problems. The view of rust is rather that they’re not safety problems. Whether they’re correctness problems is more complicated: in general they are, but there are lots of cases where they’re not, like short-running processes (once the process terminated it’s memory is reclaimed so freeing it is unnecessary overhead), or FFI (you’re moving memory out of your purview, you can’t know whether it’ll be disposed of anymore).
- deleted 4y ago[deleted]