Page 1 of 1
My 10-year-old's concept of memory leaks
Posted: Sun Dec 04, 2016 1:39 pm
by Dude
I was talking to my 10-year-old son about programming, and how everything has to be in a specific sequence and that you can't leave any steps out. I then used the old "make me a peanut butter sandwich" analogy to demonstrate.
I asked him the exact steps required to make the sandwich. I prompted him with, "You open the fridge. Then what?" He said, "get the margarine, and open the pantry" (to get the peanut butter). But then he
immediately said, "No, wait, close the fridge first and THEN open the pantry."
I was so proud of him and I explained that was correct because he just prevented a "memory leak".
I thought it was cool, anyway.

Re: My 10-year-old's concept of memory leaks
Posted: Sun Dec 04, 2016 3:09 pm
by TI-994A
Dude wrote:...then he immediately said, "No, wait, close the fridge first and THEN open the pantry."
...I explained that was correct because he just prevented a "memory leak".
Clearly a smart kid!
However, you might have given him the wrong idea. Memory leaks are not necessarily caused by sequence, but rather by failure to clean-up. It might be a drain on resources, but it would have been absolutely legal for him to
close the fridge even after making the sandwich.

Re: My 10-year-old's concept of memory leaks
Posted: Mon Dec 05, 2016 12:27 am
by Dude
Very true! I prefer to close/free something as soon as it's no longer needed, though.

Re: My 10-year-old's concept of memory leaks
Posted: Mon Dec 05, 2016 3:49 am
by TI-994A
Dude wrote:Very true! I prefer to close/free something as soon as it's no longer needed, though.

Best practices!

Re: My 10-year-old's concept of memory leaks
Posted: Mon Dec 05, 2016 5:40 am
by Lunasole
Funny story. You're doing right btw, such analogies teaching child much better than dry theory (well, not childs only ^^), and they also involving abstract thinking
Re: My 10-year-old's concept of memory leaks
Posted: Mon Dec 05, 2016 7:39 am
by normeus
I would call that open door, a power drain!
just because I am currently programming buggy xcode iPhones !

Re: My 10-year-old's concept of memory leaks
Posted: Mon Dec 05, 2016 8:18 am
by Mistrel
If you forget to close the fridge then all of the food (objects) inside will run out of cold air (memory) and expire (program crash).
I thought your story was cute.
I can still remember how hard it was for me to make the jump from a gosub with globals to functions with scope and a return value. I sat on the floor trying to figure it out for hours.