Red

Red

Rust Brain Teasers: leaking loop running forever? (page 50)

The author apparently contradicts himself, since in the discussion it becomes apparent that the program will be terminated after running for a while. So it’s definitely not running forever, and that’s the surprise in this puzzle.

Most Liked

herbert

herbert

Author of Hands-on Rust

The “Amnesia” teaser really is a double-layered puzzle, structured to teach the reader about a common Rust misconception.

A loop without a break will run forever (in as much as any process can run forever; eventually it’ll be terminated). So that’s not meant to be surprising: you can see there’s a loop and no break or terminate, panic or other process ending call.

In this case, it’s quietly leaking just under 4k of RAM per loop iteration–so eventually it will grind to a halt, and depending upon your Operating System’s “OOM killer” setup may be terminated.

The real surprise—and purpose of the teaser, from a teaching point of view—is to highlight that Rust’s extensive memory guarantees explicitly do not include protection from memory leaks. The language makes it tricky to accidentally leak memory, but it can be done. Even more surprisingly, forget and its ilk explicitly create memory leaks! That seems to fly in the face of what is expected from “memory safety”–so the discussion leads into covering why a) this isn’t a guarantee, and b) you may occasionally actually want to leak memory.

I hope that clears up the thought process a bit.

Popular Prag Prog topics Top

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
lirux
Hi Jamis, I think there’s an issue with a test on chapter 6. I own the ebook, version P1.0 Feb. 2019. This test doesn’t pass for me: ...
New
mikecargal
Title: Hands-on Rust: question about get_component (page 295) (feel free to respond. “You dug you’re own hole… good luck”) I have somet...
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
AleksandrKudashkin
On the page xv there is an instruction to run bin/setup from the main folder. I downloaded the source code today (12/03/21) and can’t see...
New
jeremyhuiskamp
Title: Web Development with Clojure, Third Edition, vB17.0 (p9) The create table guestbook syntax suggested doesn’t seem to be accepted ...
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
New

Other popular topics Top

Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
AstonJ
Chris Seaton, the creator of TruffleRuby has died. It appears from suicide :cry: He left this note on Twitter on the weekend: And one...
New

Latest in PragProg

View all threads ❯