Java's Garbage Collection Explained - How It Saves your Lazy Programmer Butt

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 พ.ค. 2024
  • This is how Java does memory management through garbage collection!
    ☕ Complete Java course: codingwithjohn.thinkific.com/...
    Ever wondered how garbage collection works in Java? Java handles a lot of memory management by itself behind the scenes, so you never have to think about it. We'll talk about what it cleans up, and how it does it in a simple way that even beginners will easily understand!
    Learn or improve your Java by watching it being coded live!
    Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java learners.
    Let me know what else you'd like to see!
    Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
    📕 THE best book to learn Java, Effective Java by Joshua Bloch
    amzn.to/36AfdUu
    📕 One of my favorite programming books, Clean Code by Robert Martin
    amzn.to/3GTPVhf
    🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
    www.audibletrial.com/johnclean...
    🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
    bit.ly/3QPNGko
    📹Camera I use for recording:
    amzn.to/3wlXcmR
    🎙️Microphone I use (classy, I know):
    amzn.to/3AYGdbz
    Donate with PayPal (Thank you so much!)
    www.paypal.com/donate/?hosted...
    00:00 Why Do We Need a Garbage Collector?
    01:49 How Java Chooses What to Dump
    03:56 How Else Can It Become Abandoned?
    05:17 How the Garbage Collector Works
    08:00 What Next?
    08:45 BONUS
    ☕Complete Java course:
    codingwithjohn.thinkific.com/...
    codingwithjohn.com

ความคิดเห็น • 109

  • @Phoenix-od2bp
    @Phoenix-od2bp 6 หลายเดือนก่อน +44

    ⁠Hi John, loving your videos. I am a senior Java Developer too and your explanations help me reaffirm my understanding and most of the time declutter my misunderstanding.
    You are excellent at what you do. Request you to consider a course on Design Patterns. Ty!

    • @thirdstreetnorth
      @thirdstreetnorth 6 หลายเดือนก่อน +4

      umm I would gladly PAY for design patter course from John with concrete, commercial examples (instead of cats and dogs in that case) 😅

  • @dr.sweetlove1349
    @dr.sweetlove1349 6 หลายเดือนก่อน +15

    Your ability to effectively simplify complex topics with the exact right amount of information is impressive. Thank you for sharing your insight!

  • @iparadoxg
    @iparadoxg 6 หลายเดือนก่อน +9

    Besides the excellent coding tutorial, I come here to John's uplifting presence and his joyful smile.❤

    • @CodingWithJohn
      @CodingWithJohn  6 หลายเดือนก่อน +6

      Thanks! I'm always nervous I might be a bit too silly with stuff like this video has, but putting it in makes me happy. So I hope others enjoy it as well.

    • @BravePro
      @BravePro 6 หลายเดือนก่อน

      @@CodingWithJohn The vids are explained in a very ez and understanding manner. It's just your style. Silly or not some people will like it, others won't. Don't worry about people's opinions. Love the vids!

  • @JB-gv7pt
    @JB-gv7pt 6 หลายเดือนก่อน +3

    Thank you, John. I'm still in school and constantly feel like I know nothing, but watching your videos and genuinely learning something makes me feel slightly better lol. Thank you for what you do.

  • @TheXxEvolution
    @TheXxEvolution 6 หลายเดือนก่อน

    Good to see you back, pal! Never thought about GC as you said, but this was a really good understandable explanation of getting into it

  • @ensarmakas4904
    @ensarmakas4904 6 หลายเดือนก่อน +4

    I had some questions about garbage collection and multithreading for java in an interview. This video opened my mind about java. I was thinking like, Oh, i know java. But there is much to learn i guess. Thanks a lot!

  • @zxtqwwr0
    @zxtqwwr0 6 หลายเดือนก่อน

    Great tutorial John, thank you for the video ! Please keep up with such more complex concepts, you are a great teacher.

  • @i_1nsaan
    @i_1nsaan 6 หลายเดือนก่อน +48

    Make a video on how to optimize java code's performance!

    • @guinea_horn
      @guinea_horn 6 หลายเดือนก่อน +11

      This is such a generic request, "optimizing Java code" is far too broad of a subject to address

    • @i_1nsaan
      @i_1nsaan 6 หลายเดือนก่อน +1

      @@guinea_horn if you can direct me to some resources it would be helpful.

    • @ericpenrose3649
      @ericpenrose3649 6 หลายเดือนก่อน +4

      If you want a broad strategy on how to generally write more performant code in Java, that can be summed up into a single sentence: "Use Javas built-in tools as much as possible, and make sure you research that its intended use matches what you're doing with it". The problem with a question so broad is that every instance of 'optimizing performance' is a unique type of problem and would require just as many videos. If you look at Johns catalogue you will find many videos that touch on individual problems and the considerations when optimizing them. But he doesn't have infinite videos.
      Say you're trying to optimize a custom sort on an array of json objects, are you trying to optimize for execution speed or memory management? Both are different types of performance. Both will have different considerations and may be done entirely differently. Optimizing a custom sort of a different type of object might also have its own set of approaches for either speed or memory. But back to my first point, if there is a built-in Java object type or method meant to do the thing you are trying to do, it is a more mature solution than your custom sorter would be. It will likely be reasonably efficient with both speed and memory, and will catch more edge-cases and have more informative errors for them than a custom solution.

    • @i_1nsaan
      @i_1nsaan 6 หลายเดือนก่อน

      @@ericpenrose3649 Thanks man!

    • @dubble
      @dubble 6 หลายเดือนก่อน

      Don't use Java for performance critical code. Outside of that, it's about the same as for every other managed language: make use of the library and write simple code. Performance is generally good enough and it prevents you from shooting yourself in the foot. If that's not good enough, really, don't use the JVM.

  • @alex0917lfo
    @alex0917lfo 6 หลายเดือนก่อน

    I am being studying and work with Java very long time , but Only John's video I love the most! Nice video as always. Is that possiable you can talk about Comparator ?

  • @Lykkos29
    @Lykkos29 6 หลายเดือนก่อน +1

    Your videos are always a must for me

  • @misaonthefly
    @misaonthefly 2 หลายเดือนก่อน

    I really appreciate your effort with these videos

  • @levon9
    @levon9 6 หลายเดือนก่อน

    Nicely done - thanks for sharing.

  • @aminesafi7261
    @aminesafi7261 6 หลายเดือนก่อน

    Great video, complex topics require simple explanation, keep going :)

  • @justmastiii4966
    @justmastiii4966 6 หลายเดือนก่อน

    Really a very helpful video and the way of explanation is awesome ❤❤❤❤❤❤❤

  • @denniskaranja6578
    @denniskaranja6578 6 หลายเดือนก่อน +2

    Kindly do dynamic programming , you make the complicated so simple .much love from Kenya

  • @SUMITYADAV-cy9hf
    @SUMITYADAV-cy9hf 3 หลายเดือนก่อน

    hey John !!! amazing work requesting you to create a spring framework course as well .

  • @samuelnilsson5505
    @samuelnilsson5505 5 หลายเดือนก่อน

    No bs, straight to the point showing us how its done.

  • @muhammedbeyhanus5416
    @muhammedbeyhanus5416 6 หลายเดือนก่อน

    bonus part is awesome :D

  • @Metorrite
    @Metorrite 2 หลายเดือนก่อน

    John, love your content, i'm primarily self taught and want to turn this into a career after my current obligations. I had some ideas i'd love to see from you, one being for people like myself, of which there are many, is a video detailing many of things that get overlooked when self taught, for example, how array lists and linked list differ performance wise (This isn't the best example but hopefully you get the idea), there are lots of things overlooked when getting from point A to point B being self taught and it could be really useful. A more simple idea i would love to see is a video teaching use about bitwise operators and how they are used and work, or maybe a video talking more about bigger picture things like using version control with git and team environments, love the content, keep it up!!!

  • @sianke1991
    @sianke1991 6 หลายเดือนก่อน

    Good to see you again.

  • @abdelmoneimelshafei6570
    @abdelmoneimelshafei6570 6 หลายเดือนก่อน

    You're the best java teacher i never have
    thank you very much, very helpful video

  • @rileygriffith2055
    @rileygriffith2055 6 หลายเดือนก่อน

    Thank you for making this video.

  • @yte6598
    @yte6598 6 หลายเดือนก่อน +1

    I often heard garbage collection but hadn't understood it's mechanism at all. It doesn't affect my Java coding much to learn fundamental concept, But I think it will help me code properly. Your videos very easy and helpful to understand fundamental concept about programming for beginner. many thanks!

    • @artofcomputing-art
      @artofcomputing-art 4 หลายเดือนก่อน

      I was just recommended this video about Java Garbage Collection, and I don't even use Java, but let me give you some advice: Learn the fundamentals, they may not make much sense for you now, but boy they will save your ass down the line

  • @melzasmaldoran855
    @melzasmaldoran855 6 หลายเดือนก่อน

    Hey John! I would love to see a video about Ressource bundle :)

  • @gopalkannan4934
    @gopalkannan4934 5 หลายเดือนก่อน

    Happy New year 🎉🎉🎉🎉

  • @Hiphophamer
    @Hiphophamer 6 หลายเดือนก่อน +2

    Love those first 2 seconds 😂 ❤

  • @rnages1921
    @rnages1921 6 หลายเดือนก่อน

    Thank you John, I was looking for a content regarding GC. I owe you a coffee.

  • @anushakandagal1727
    @anushakandagal1727 3 หลายเดือนก่อน

    simple and clean !!

  • @lliaams
    @lliaams 6 หลายเดือนก่อน

    Amazing video ❤

  • @maheshmadathil
    @maheshmadathil 6 หลายเดือนก่อน

    Thanks John for the wonderful explanation. Cud u pls talk about System.gc() and finalize() methods as well in the next part?

  • @DeltaXML_Ltd
    @DeltaXML_Ltd 6 หลายเดือนก่อน

    Great video 😁

  • @LukasOwen
    @LukasOwen 5 หลายเดือนก่อน

    a part of gc that i find interesting is WeakReference and SoftReference, which indicate to the gc that although this object is referenced it can still be collected now or whenever you really need to free the space

  • @maheshkandula1119
    @maheshkandula1119 6 หลายเดือนก่อน

    Thank you for the video! Could you create another one focusing on RestTemplate and WebClient? I'm aware RestTemplate is being phased out, but could you explain the reasons behind it?

  • @MissPiggyM976
    @MissPiggyM976 6 หลายเดือนก่อน

    Please, more on better memory management!

  • @mhd71313
    @mhd71313 4 หลายเดือนก่อน

    I love for your videos. where are you? we miss you!. can you make a video about stream and how to use it to filter or map ? thank you

  • @gerdsfargen6687
    @gerdsfargen6687 6 หลายเดือนก่อน

    John's back!! 😃

  • @Roe124
    @Roe124 6 หลายเดือนก่อน

    Hi John. I love your vids. I even subscribed to your course which has helped me immensely. I have a request.. Can you maybe do videos on JavaFX too? Thank you so much ! Meow!

  • @Kxliderr
    @Kxliderr 4 หลายเดือนก่อน

    Does your java course go over recursive methods? Thanks

  • @publicstaticvoid1010
    @publicstaticvoid1010 6 หลายเดือนก่อน

    Nice, your explanation is awesome, genuinely never understood what garbage collection is. Idk even know what "in memory" really means and where that memory is💀
    Is there a way to see all these garbage collection processes in real time whilst programming?

    • @itzdm0r3
      @itzdm0r3 6 หลายเดือนก่อน

      "In memory" meaning data stored in a computers RAM and sometimes ROM. When computers run out of memory it creates an overflow exception.

    • @publicstaticvoid1010
      @publicstaticvoid1010 6 หลายเดือนก่อน

      @@itzdm0r3 cool, I'll check that further out

  • @aldoumene6201
    @aldoumene6201 4 หลายเดือนก่อน +1

    Hello John :) can you please make a video about spring boot? It’s so useful but so confusing still for me :/

  • @shingotennichishingotennic2767
    @shingotennichishingotennic2767 6 หลายเดือนก่อน

    Hi John, do you have videos about jar, war and ear files?

  • @fahadassiry224
    @fahadassiry224 4 หลายเดือนก่อน

    plz answer me. i just finished java course with oop and data structures and when i go back to old subjects i feel that i forget it and i learn it again to memories it so plz tell what should i do. spend time on leetcode or learn spring boot and build projects because i want to be java backend developer

  • @nvdice
    @nvdice 6 หลายเดือนก่อน

    Would you be able to create videos for other framework GCs as well. For example node.js

  • @wellingtondefassio4435
    @wellingtondefassio4435 6 หลายเดือนก่อน

    that is amazing content :)

  • @elizabeth00653
    @elizabeth00653 4 หลายเดือนก่อน

    John more leetcode explanations please!

  • @Soumyajit_619
    @Soumyajit_619 4 หลายเดือนก่อน

    Can you start a playlist on Spring/ Spring Boot... Our guest lecturer is running on a jet RN and ofcourse we can't catch up 🙃

  • @hrabei8745
    @hrabei8745 5 หลายเดือนก่อน

    many thanks for your tutorial clips, but as a beginner I don't know what is the first and what is the last clip, I mean it is better you put a number for each clip so everyone can watch them in order

  • @mrchaherbahri1944
    @mrchaherbahri1944 6 หลายเดือนก่อน

    we need a tutorial about tokners and input/output data please mighty John we rely on you

  • @mostafasaleh2806
    @mostafasaleh2806 6 หลายเดือนก่อน

    Could you recommend books for java developers

  • @mohamohai9840
    @mohamohai9840 6 หลายเดือนก่อน

    Thanks mate. By the way, how is your junior dev going? 😊

  • @personalaccount1515
    @personalaccount1515 6 หลายเดือนก่อน

    Greetings dude ✌️

  • @dylanngo4454
    @dylanngo4454 4 หลายเดือนก่อน

    Thank bro, Keep make new videos

  • @livingzombie553
    @livingzombie553 หลายเดือนก่อน

    enjoyed laerning

  • @elhombredesangrenegra3438
    @elhombredesangrenegra3438 6 หลายเดือนก่อน

    Is there a way to free up the space manually if I know that the object wont be used anymore?

    • @CodingWithJohn
      @CodingWithJohn  6 หลายเดือนก่อน

      You can suggest that the garbage collector run by calling System.gc();, but this doesn't guarantee it will actually do it. I've never had to do this in my entire career, I've always been able to rely on the garbage collector to do its job without any management.

  • @derechtepilz
    @derechtepilz 6 หลายเดือนก่อน

    So if I just created an object but never assigned that object to a variable, that means to a reference in memory, that object would get garbage collected basically immediately?

    • @CodingWithJohn
      @CodingWithJohn  6 หลายเดือนก่อน +3

      Yep, it would at least be eligible! If your whole line of code was just:
      new Cat();
      It's immediately unreachable. It wouldn't necessarily go away immediately because GC works in batches, but in the next round of collection it would definitely be gone.

  • @tipeon
    @tipeon 6 หลายเดือนก่อน +1

    Once upon a time, I had some colleagues who believed that setting a variable to null somehow "helped" the garbage collector. It was difficult to convince them that it was all superstition, and that no, it wasn't doing anything.
    Sometimes, the smartest minds are also the dumbest.

    • @CodingWithJohn
      @CodingWithJohn  6 หลายเดือนก่อน

      Usually it's not necessary if the variable is scoped correctly, but it can technically do something!

  • @lidiaz0
    @lidiaz0 3 หลายเดือนก่อน

    Lovely

  • @jamesngige8560
    @jamesngige8560 6 หลายเดือนก่อน

    We want bald John back! We want bald John back! We want bald John back! We want bald John back!!!!
    Great content as always.

  • @nischalofchrist
    @nischalofchrist 6 หลายเดือนก่อน

    Heyyyy,look who's back

  • @sergiooliva2517
    @sergiooliva2517 6 หลายเดือนก่อน

    lol I loved the title of this video

  • @user-vp2vg1ql4n
    @user-vp2vg1ql4n 6 หลายเดือนก่อน

    Funny ending 😂

  • @xBradRame
    @xBradRame 6 หลายเดือนก่อน

    John my man gonna get me out of poverty 🙏

  • @ritikdwivedi5983
    @ritikdwivedi5983 6 หลายเดือนก่อน +2

    Well in the last John is just mimicking the java garbage collector when he sees any new object without any reference

    • @CodingWithJohn
      @CodingWithJohn  6 หลายเดือนก่อน +1

      GET IT

    • @ivalar8891
      @ivalar8891 6 หลายเดือนก่อน

      @@CodingWithJohn Please, don't remove me from OldGen club, I still have a lot of references.

  • @imonitieisrael4821
    @imonitieisrael4821 4 หลายเดือนก่อน

    Hello John, hello everyone; please I’m a computer science student who really wants to go into programming but I’ve still not figure out what aspect to go into; is Java a good place to start, can we create software with java? Pls I need y’all contributions and advice
    Thank you
    Btw, I wish to be a software engineer

    • @Soumyajit_619
      @Soumyajit_619 4 หลายเดือนก่อน

      Yes Java is a very good language, but you should always start your programming journey with C as it builds basic programming logic

  • @paganimarker1898
    @paganimarker1898 5 หลายเดือนก่อน

    Make video about SLL and DLL

  • @dannyalvarez4533
    @dannyalvarez4533 9 วันที่ผ่านมา

    Do an example of this topic please.

  • @HasanboyKarimjonov
    @HasanboyKarimjonov หลายเดือนก่อน

    Also my dumb brain got it. thank you so much

  • @shlomoprayev9391
    @shlomoprayev9391 6 หลายเดือนก่อน

    Ideas for new chapters: Future class, jars compilation, working with configurations, Spring

  • @user-vb1mg5fs8n
    @user-vb1mg5fs8n 6 หลายเดือนก่อน +1

    That jumpscare :{_-_-_

  • @MJ-cf9nl
    @MJ-cf9nl หลายเดือนก่อน

    This video could've been alot more complete if it included a short explanation of how does the GC figure out that an object is not referenced anymore.

  • @Arc618
    @Arc618 หลายเดือนก่อน

    The biggest reason I lean on Java/C# over C++ lol

  • @itzdm0r3
    @itzdm0r3 6 หลายเดือนก่อน +1

    In older languages you had to do memory management manually. These high level languages are great imo. 😂

  • @RajasthaniINAmerica
    @RajasthaniINAmerica 5 หลายเดือนก่อน

    👍👍👍👍

  • @Pherecydes
    @Pherecydes 5 หลายเดือนก่อน

    Why not just delete stuff as soon as it goes out of scope? I don't understand the need for the extra complexity.

  • @macculu501
    @macculu501 6 หลายเดือนก่อน

    Are those ridiculously complicated Garbage Collection details covered in your complete Java course?

    • @CodingWithJohn
      @CodingWithJohn  6 หลายเดือนก่อน

      Not at the moment, the course is more geared toward beginners. All lessons that are included are shown on the course page so anyone can make sure it's what they're looking for before moving forward.

    • @macculu501
      @macculu501 6 หลายเดือนก่อน

      @@CodingWithJohn Understood, thanks John

    • @7thSalomo
      @7thSalomo 6 หลายเดือนก่อน

      Hey John! Great course! i was wondering if you are planing on making a more advance course aswell, like a part 2 after you finish the beginner friendly one? @@CodingWithJohn cheers!

  • @Raulaar
    @Raulaar 6 หลายเดือนก่อน

    John you legend, when will you finally go for President?

  • @19891214ful
    @19891214ful 6 หลายเดือนก่อน

    So, the JGC is essentially the Davy Jones. Collecting lost souls.

  • @RussellSubedi
    @RussellSubedi 6 หลายเดือนก่อน

    So we're not dissing on Java's Collection framework then?

  • @Arfifias
    @Arfifias 5 หลายเดือนก่อน

    Alex lee is another youtuber who taught me many things and bro code as well but I cannot see the stupid front end languages surge on the market why is that????

  • @dipsrocx4028
    @dipsrocx4028 หลายเดือนก่อน

    backgroud more like - I am a lead guitarist.

  • @qwertyuiop-cu2ve
    @qwertyuiop-cu2ve 5 หลายเดือนก่อน

    Devil's advocate here: If we still have to set `ptr = null;` to make it (eventually) free the memory, from the programmer's perspective how is that anyhing more convenient than writing `free(ptr);` or `delete ptr;` as we do in C/C++ ? What problem does it solve? How is this anything different from manual memory management, except for introducing more runtime overhead?

  • @OnurGirginn
    @OnurGirginn 4 หลายเดือนก่อน

    what is your secret ?

  • @OnurGirginn
    @OnurGirginn 4 หลายเดือนก่อน

    üstad nasıl... anlat bize de bu işin sırrı ne ?

  • @djaccount5458
    @djaccount5458 3 หลายเดือนก่อน

    Brr I hate Java brrr.. but i love JavaScript.

  • @Arfifias
    @Arfifias 5 หลายเดือนก่อน

    My friend John why don't you make a video to discuss the racism that Back End Developers receive from the the stupid Front Ends because many like me are declined day by day.
    I have been declined as well but I don't care about that because to make ends meet I started youtube but anyways Front End dev's thinking is annoying from personal XP

  • @wellingtonaraujo5418
    @wellingtonaraujo5418 2 หลายเดือนก่อน

    Do you have group on discord ?