Only The Best Developers Understand How This Works

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 มิ.ย. 2024
  • JavaScript Simplified Course: javascriptsimplified.com/?utm...
    Managing memory in JavaScript is generally pretty easy because of garbage collection, but it isn’t always easy. In this video I will explain exactly what garbage collection is, how it works, and more importantly show you how you can debug and fix the most common memory related problems in your applications.
    📚 Materials/References:
    JavaScript Simplified Course: javascriptsimplified.com/?utm...
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    ⏱️ Timestamps:
    00:00 - Introduction
    00:27 - How garbage collection works
    08:00 - Memory Management Advanced Tip
    09:58 - How To Find Memory Leaks
    13:55 - WeakMap & WeakSet
    #GarbageCollection #WDS #MemoryManagement

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

  • @oscarleon3008
    @oscarleon3008 4 วันที่ผ่านมา +54

    I started watching your videos in 2020 as a way to learn. I told myself I'd self-teach myself enough to eventually land a junior job... 4 years later I still learn something new every time I watch one of your videos. And yes, I'm happily employed as a software engineer now :)

    • @dj10schannel
      @dj10schannel 4 วันที่ผ่านมา +2

      Grats

    • @WebDevSimplified
      @WebDevSimplified  4 วันที่ผ่านมา +9

      Congratulations on the job! It's a lifetime of learning. I still learn new things every week it seems like.

    • @abh1yan
      @abh1yan 3 วันที่ผ่านมา +1

      ​@@WebDevSimplifiedhave you ever tried reading the Ecmascript standards?

  • @Frexuz
    @Frexuz 5 วันที่ผ่านมา +62

    Maybe hint in the title Wtf the video is about?

    • @srdjagunjic
      @srdjagunjic 4 วันที่ผ่านมา +18

      Nah, the title is clickbait for the first few days and then he changes it to something normal. Algo playing...

    • @irahazda
      @irahazda 4 วันที่ผ่านมา +2

      @@srdjagunjic Veritasium had a video explaining this

    • @aeronwolfe7072
      @aeronwolfe7072 4 วันที่ผ่านมา

      quit b**ching

    • @GNXClone
      @GNXClone 4 วันที่ผ่านมา +1

      Because it leaves you wondering "How WHAT works?" That said, Kyle's videos are gold and worth clicking. He doesn't need to bait us, imo.

  • @NavySturmGewehr
    @NavySturmGewehr 5 วันที่ผ่านมา +36

    Would you be willing to do a bit of a deep dive into IndexedDB? I really want to figure out how to use it for state in a react application.

    • @Frostbytedigital
      @Frostbytedigital 5 วันที่ผ่านมา +3

      Dexie makes it pretty simple. They have some react specific hooks aswell but I use it in every framework for browser saved state that can take any ... even files!

    • @denverjamesduran2750
      @denverjamesduran2750 4 วันที่ผ่านมา

      Hey man you should definitely look up for tinybase. It offers reactivity and supports indexedDB too

    • @NavySturmGewehr
      @NavySturmGewehr 4 วันที่ผ่านมา

      @@Frostbytedigital Yeah, there is a fair amount of data I want to store that would do best in a database style method of storage!

    • @lsavio5165
      @lsavio5165 วันที่ผ่านมา

      Try SQL lite

  • @harleyspeedthrust4013
    @harleyspeedthrust4013 4 วันที่ผ่านมา +8

    some of the comments are a little mean. the title is accurate; only the best developers know how memory works in v8 (and in general). you don't become a great developer by hopping javascript frameworks every week.

  • @lakhveerchahal
    @lakhveerchahal 5 วันที่ผ่านมา +4

    This one was very informational! Great work Kyle!

  • @neelthakkar4492
    @neelthakkar4492 5 วันที่ผ่านมา +1

    Great insight about how to debug memory leak. Thanks for the information.

  • @nitsanbh
    @nitsanbh 3 วันที่ผ่านมา +6

    5:09 "Any time you use a string, a number, a boolean - those [primitive values] will stay in memory forever, because they are not being garbage collected."
    Very inaccurate. Let's explain.
    Not all primitives are the same: some are stored in the heap, and some are in-place.
    Small integers (up to 31 bytes) and booleans are in-place. They don't need clean-up (they'll be freed when the thing that holds them is freed).
    Larger integers (and floating point numbers) ARE stored in the heap. They are held by a pointer and they do need clean-up.
    All strings are stored in the heap!
    and hence, they WILL BE cleaned up, unlike what Kyle says.
    The reason that "innerString" wasn't cleaned is because V8 employs an optimization strategy called "Interning". Since people use strings pretty-much like enums, V8 keeps small strings in memory for longer, to avoid re-allocating them later.

    • @marketfinds
      @marketfinds 3 วันที่ผ่านมา +2

      I was going to ask if you are worried about memory then using classes more would result in better cleanup but doesn't sound like the case. Good video otherwise.

    • @gurusystem
      @gurusystem วันที่ผ่านมา +2

      The other reason the "innerString" was retained in memory is because it is console logged, so the engine has to keep it in memory in case the DevTool needs to inspect it.

  • @aeronwolfe7072
    @aeronwolfe7072 4 วันที่ผ่านมา

    good info Kyle. I learn something new from you all the time!!!! I appreciate you man!!!!!!!!!!!!

  • @hut_fire1490
    @hut_fire1490 5 วันที่ผ่านมา

    Thanks Kyle ! Its very informative

  • @todd.mitchell
    @todd.mitchell 4 วันที่ผ่านมา

    Perfect timing! Thanks for this.

  • @e.manowseapoe5359
    @e.manowseapoe5359 5 วันที่ผ่านมา

    Awesome video thank you so much!

  • @reactjs1900
    @reactjs1900 2 วันที่ผ่านมา

    I really needed this. Thanks 👍

  • @gkiokan
    @gkiokan 4 วันที่ผ่านมา

    Interesting. Keep up the good work. I am doing Enterprise Development for 11 Years now and never had to use this. Following best practices and writing clean code helps for sure. But once you might need to debug your Memory and Performance, this is quite a good Guide as to where to start from. Good Job man.

  • @timoBike
    @timoBike 4 วันที่ผ่านมา

    Really appreciate this video. Is possible to have another video to talk about how to find memory leak efficiently in Node JS service ?

  • @OudinAlex
    @OudinAlex 5 วันที่ผ่านมา

    Not really what I would call a memory leak, but we get the concept. Nice video

  • @abu2musa
    @abu2musa 4 วันที่ผ่านมา

    The debugging video and this one are like goldmines for developers. I always wondered why the performance part and debugging in chrome browser is not thought as it makes life so much easier.

  • @colindante5164
    @colindante5164 5 วันที่ผ่านมา

    Thanks for the upload. ))

  • @ev721
    @ev721 วันที่ผ่านมา

    Damn! This was extremely informative.

  • @aurelionsoul9125
    @aurelionsoul9125 5 วันที่ผ่านมา +1

    recently learned Javascript, is it possible to make a pixelated multiplayer game, sandbox style or top down

  • @paradox3210
    @paradox3210 4 วันที่ผ่านมา

    You can expose the GC and then trigger it with the little broom icon. That way, your snapshots are always "clean". I am currently struggling with a memory leak with Nuxt SSR - a small example like yours is easy, but as soon as you have a whole enterprise app, it gets really difficult to isolate things 😑

  • @iTzBoosTerZx
    @iTzBoosTerZx 2 วันที่ผ่านมา

    I never noticed how much you move your head when speaking, but now I can’t unsee it

  • @doppeltevier
    @doppeltevier 2 วันที่ผ่านมา

    Could you create a video about Atlassian's new framework-agnostic, low-level dnd library called "pragmatic-drag-and-drop"?

  • @SperkSan
    @SperkSan 4 วันที่ผ่านมา

    I have been using JavaScript for about 4 years and never knew there was a WeakMap class

  • @ChrissyCode
    @ChrissyCode 5 วันที่ผ่านมา

    WeakMap i only use, when for example i want to figure out if data is duplicated or already added or not.
    But i could also just use a normal map, and clear it after the function.
    Or the map also get's cleared if initialized inside of the same scope

  • @kamertonaudiophileplayer847
    @kamertonaudiophileplayer847 4 วันที่ผ่านมา

    Sure, only the best, and I am glad that I and you are the best.

  • @karimbouche3563
    @karimbouche3563 5 วันที่ผ่านมา

    Really interesting

  • @Gigawattt
    @Gigawattt 11 ชั่วโมงที่ผ่านมา

    In Chrome, is there a difference between opening an “incognito” window and just opening a Guest profile window? Both seem to give you no extensions, a clean history, and empty cache?

  • @yeabsragebriel32
    @yeabsragebriel32 5 วันที่ผ่านมา

    It's best tutorial but can you make another js master like challenge or exercise even to master it 😊😊😊

  • @migy220
    @migy220 4 วันที่ผ่านมา

    For example, in react. can we view the data stored in memory under the Memory?

  • @ukaszzbrozek6470
    @ukaszzbrozek6470 4 วันที่ผ่านมา

    Thank you! I had a blank spot in my knowledge.

  • @MinhNguyenTao
    @MinhNguyenTao วันที่ผ่านมา

    Okay. Now I think I'm one of the best developers.

  • @shooting4star2023
    @shooting4star2023 5 วันที่ผ่านมา +2

    A bit of misinformation in the video. Values of primitive/scalar types are also subject to garbage collection, not just reference types.

  • @potaetoupotautoe7939
    @potaetoupotautoe7939 5 วันที่ผ่านมา

    dark mode plz, luv ur content btw

  • @dweblinveltz5035
    @dweblinveltz5035 4 วันที่ผ่านมา +1

    Isn't it a bit misleading to say that "primitives stay in memory forever?" True, they aren't stored in the exact way objects are. If you're declaring them on the global scope (or maybe even within the {} scope as you created in this video), then yes, they will likely stay in memory, but declaring them inside of a function (which is after all a specialized object) will reallocate their memory when the function's scope is popped off of the stack. Assuming the function isn't alive for the entirety of your running application, the primitives won't live forever.

    • @thekwoka4707
      @thekwoka4707 3 วันที่ผ่านมา

      Yes, he was just wrong on that. String literals are kept around (they exist directly in the code, so it's assumed they are likely to be used again), and also the console that the string was logged to is in memory as well, so the string is still in use in the console.

  • @RandomGeometryDashStuff
    @RandomGeometryDashStuff 4 วันที่ผ่านมา

    05:10 what about strings that don't exist in source code but created dynamically like `Date()`?

    • @yatinarora1252
      @yatinarora1252 2 วันที่ผ่านมา +1

      see date exists on window object,so i will be staying in memory but date that we created will be holding in a variable that will be cleared by garbage collector.

  • @dweblinveltz5035
    @dweblinveltz5035 4 วันที่ผ่านมา +2

    OK yo, I've been an JS engineer for years, I legit did not know you could just use curly braces by themselves to make a scope.

  • @pankajwp
    @pankajwp 5 วันที่ผ่านมา

    Gold

  • @6r31v1nZ
    @6r31v1nZ 4 วันที่ผ่านมา

    why does anyone ever talks about memory leaks in JS?

  • @thirdreplicator
    @thirdreplicator 23 ชั่วโมงที่ผ่านมา

    Try wearing a neck brace.

  • @gurusystem
    @gurusystem วันที่ผ่านมา

    The engine does GC before taking heap snapshot, you need to look at the retain path to see why there are three Test objects in memory. This video has multiple mistakes and inaccurate information. Please double check.

  • @NeoniumOxide
    @NeoniumOxide 5 วันที่ผ่านมา

    Hi

  • @Sankaritarina89
    @Sankaritarina89 4 วันที่ผ่านมา

    you have a dog? 🤩

    • @WebDevSimplified
      @WebDevSimplified  4 วันที่ผ่านมา +1

      I have had her for a few years. She usually sleeps in my office while I work, but tends to leave when I start recording videos since she doesn't like it when I move around all my lighting equipment. She must have been really tired when I recorded this, though, as she didn't move an inch.

  • @thekwoka4707
    @thekwoka4707 3 วันที่ผ่านมา

    Lots of wrong things
    Your strings were kept in memory because they were string literals in the code, not because they were strings. Numbers are also collected, but don't have memory anyway, since they are raw pointers.
    You actually didn't talk at all about how garbage collection works in the section for "how garbage collection works".....

  • @Dorgrident
    @Dorgrident 5 วันที่ผ่านมา +7

    "You must know this!"
    "Only The Best Developers Understand How This Works"
    I think its called clickbait and alot of people know how it works.

    • @bharatchakrabarthy7571
      @bharatchakrabarthy7571 5 วันที่ผ่านมา +2

      Yeah i commented about the same thing on one of Kyles other video too where he kept the title too abstract and makes a soy face in the thumbnail. I don't understand why he can't just tell what the video is about in the title, will make it very easy to search in future and also know what I'm getting into before clicking the video.

    • @naught0
      @naught0 5 วันที่ผ่านมา +1

      @@bharatchakrabarthy7571 Because that's not how you make money on youtube lol

    • @LupoTosk96
      @LupoTosk96 5 วันที่ผ่านมา +2

      Especially in the web scene where many people get a job without being qualified developrers, these concepts and specifically how to profile their JavaScript is barely known. I've been working in a web agency and except for two of twendy developers nobody knew about let and const, didn't even how what a class is (neither in JavaScript nor the general concept). Most of them didn't even use var, their coding standard was just huge files of implicitly declared global variables and functions.
      His titles are useless clickbait though... none of these people will ever find his videos when specifically searching for such information, contributing to the mess by making useful information not usefully accessible.

    • @fullstacklarry
      @fullstacklarry 4 วันที่ผ่านมา

      Thats who usually gets the jobs, people who don't know shit and might have a degree....

    • @thekwoka4707
      @thekwoka4707 3 วันที่ผ่านมา

      Even worse that he's wrong on quite a lot of things and doesn't actually tell how garbage collection works...despite half the video being that section...

  • @RobbPage
    @RobbPage 4 วันที่ผ่านมา +1

    enough of the clickbait titles. please just say WHAT your video is about. I'd hate to unsub after all these years but i don't play that clickbait bullshit.

  • @seandavidson3602
    @seandavidson3602 3 วันที่ผ่านมา

    I always lose concentration on your videos when you pronounce the W in known and own etc. I just can't. I start googling trying to find out which dialect does this, and I'm told that none do. It;s just you. lol

  • @kazmi401
    @kazmi401 5 วันที่ผ่านมา

    ClickBait!

  • @CrashPreinsertion
    @CrashPreinsertion 5 วันที่ผ่านมา +5

    Absolutely awful title & screenshot. 👎

    • @HartleySan
      @HartleySan 5 วันที่ผ่านมา +3

      Clickbait, no?

  • @Malediction99
    @Malediction99 5 วันที่ผ่านมา

    Bro, just buy another guitar stand.

  • @uditvish726
    @uditvish726 4 วันที่ผ่านมา

    [].forEach.call(
    document.querySelectorAll('*'),
    function(el) {
    if (el.offsetWidth > docWidth) {
    console.log(el);
    }
    }
    );

  • @uditvish726
    @uditvish726 4 วันที่ผ่านมา

    [].forEach.call(
    document.querySelectorAll('*'),
    function(el) {
    if (el.offsetWidth > docWidth) {
    console.log(el);
    }
    }
    );

  • @uditvish726
    @uditvish726 4 วันที่ผ่านมา

    [].forEach.call(
    document.querySelectorAll('*'),
    function(el) {
    if (el.offsetWidth > docWidth) {
    console.log(el);
    }
    }
    );

  • @uditvish726
    @uditvish726 4 วันที่ผ่านมา

    [].forEach.call(
    document.querySelectorAll('*'),
    function(el) {
    if (el.offsetWidth > docWidth) {
    console.log(el);
    }
    }
    );

  • @uditvish726
    @uditvish726 4 วันที่ผ่านมา

    [].forEach.call(
    document.querySelectorAll('*'),
    function(el) {
    if (el.offsetWidth > docWidth) {
    console.log(el);
    }
    }
    );