Garbage Collection (Mark & Sweep) - Computerphile

preview_player
Показать описание
How does memory management work? In C you had to manage things yourself, but modern languages take care of a lot of it for you - Laurence Tratt of Kings College London explains.

Laurence recommends the book 'The Garbage Collection
Handbook: The Art of Automatic Memory Management' (2nd ed.) for those
interested in exploring this subject in more detail.


This video was filmed and edited by Sean Riley.


Рекомендации по теме
Комментарии
Автор

This Gent has ability of explaining complex topics, in extremely simplified way, which is phenomenal. Please, 🙏 do more videos with him, diving in all possible topics.Respect

exaaltare
Автор

i love the clarity of Laurence's examples and explanations

njdarda
Автор

Laurence is probably my favorite person on the channel, he's able to simplify and explain things so incredibly well with a lot of humor

sanderbos
Автор

As a C# programmer you often don't spend much time thinking about garbage collection because it just works silently in the background - until you start interfacing with native unmanaged code, and then you go though a hard school of troubleshooting, having to learn how the runtime actually manages your objects in memory and why it constantly keeps moving them around.

pfefferle
Автор

You didn't mention what people normally say is the main disadvantage of garbage collection which is that it pauses the program every now and then (but there are some clever ones that can run on a different thread)

circuit
Автор

15:56 Note: Turning off and on again is the time tested workaround for memory leaks, but definitely not a fix in itself, that's up to the developer. (I know this is what he meant, I'm just clarifying for others who might not know better.)

scbtripwire
Автор

Most modern computers maintain a virtual address space for each process. That means that pointers aren't really a direct reference to a "physical part of the chip". Inside the CPU, the address translation hardware converts the virtual address to a physical one. Pages of memory are swapped in and out as needed, so a process can use more memory than is physically present on the machine. That makes programming vastly easier in some ways and vastly more difficult when things go wrong.

marksilverman
Автор

Really good account! Underneath there’s another story that’s also interesting - how should the operating system allocate memory - this was a subject of debate in the early days of OS design when memory was much more limited. Donald Knuth analysed three options: first fit (take the first free chunk that’s greater than the size needed), best fit (take the chunk that’s nearest in size to the desired amount) or a binary chop method called the buddy system. Somewhat non-intuitively the first fit works better than best fit for long term stability!

Richardincancale
Автор

Love that laptop, I've got one as well (It's called a Framework and is designed to be customizable and repairable)

coreymartin
Автор

I literally love your channel, the way you create videos, the instructors and the topics you make video about are just awesome . thanks for your serve to the community

mahdizarepoor
Автор

So nice seeing framework laptop in the wild. Good job man! Excellent choice.

MladenMijatov
Автор

There are also some downsides to the garbage collection. In many cases, esp. smaller programs the user will not notice them. I am maintaining an enterprise application written in Java which needs to run on a machine with 1 TB of RAM (yes, terabyte) and there I did experience some problems. For example, the GC did sometimes run for more than an hour (yes, more than 60 minutes) and all connections to the outside world including the database ran into timeouts, because of the "stop the world" nature of the GC. That's the reason why the GC has all these fuzzy parameters to get control of those situations but as an user, you are just buying an application and you want to use it and not get an expert in Java GC to run it. It gets even more complicated with all these different JVMs available. The IBM JVM runs different to the Oracle JVM and the GCs have different parameters. So if someone is able to solve this in Oracle JVM with some cool parameter settings you may still struggle with the problem because these parameters simply do not exist in IBM JVM. Someone might argue to choose hard- and software from different vendors than IBM, but then Java is not write once run everywhere. In my opinion the GC is a tool to make the life of the programmer easier but in some circumstances the price is it will make the life of the user harder. However the user is the last one who should deal with memory management of the application.
There are also other problems e.g. you cannot take advantage of CPU memory access optimization like prefetch.

paxrsi
Автор

this was really fun, i always wondered how garbage collectors work but never searched for it

could you guys maybe do a video on different memory management strategies? like Rust's borrow checker?

jvcmarc
Автор

really happy to see the framework laptop

janblaha
Автор

Computerphile is such a gem! cheers from Chile and thanks for all the top content you share!

tan.nicolas
Автор

On a completely unrelated point to garbage collection, I love seeing Framework laptops and Neovim in the wild!

hasan_haja
Автор

Never is a strong word; there are many programs where you do know exactly what you'll need and never perform dynamic allocation, or at least only on the stack... no heap allocation. This is especially true in embedded programming.

superjimnz
Автор

I immediately noticed the framework laptop. Nice to see other people using them, especially in more popular videos like this one!

danielbrenot
Автор

My first experience with garbage collection was in AppleSoft BASIC on an Apple II+ circa 1982. I was working on a program that read text from a file and put it onscreen, but it had to find where words ended and insert returns so no words were split at the end of one line and the beginning of the next. AppleSoft programs sit at the bottom of RAM, and numeric variables are stored from the end of the program up while strings are stored from the top of RAM down. As strings are changed, the old value stays where it was and the new value is added. This program (which my boss had written) ran fine for a while, but would periodically pause for a couple minutes while producing a screen of text. It turned out AppleSoft had run out of RAM, and was moving all the current string values back to the top to clear out the old values that weren’t being used anymore. And the way it was written, building a word one character at a time until it found a space, there were A LOT of old strings! We solved the problem by using AppleSoft’s command to trigger garbage collection manually at the end of a page before printing “Press RETURN to continue.” That was fun to figure out, considering I barely even knew what a computer was two years earlier.

DennisKovacich
Автор

I've spent a lot of time tracking down memory leaks in C programs. I'm currently doing some C# development. With user interface code, databases and REST APIs I'm spraying objects and memory all over the place, but it doesn't (usually...) get confused.

marsgal