Immutability makes code BETTER! • Episode 4 • Functional Programming in Typescript

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ก.ย. 2024

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

  • @Pptruenoz
    @Pptruenoz 8 หลายเดือนก่อน +1

    Good video 👍

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

    since the destructuring (...) creates a temp location in memory, how does the garbage collection works, do we end up leaking memory?

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

      Good question! I *believe* that the garbage collector will clean up anything (on some schedule) that does not have a pointer to it in scope. So a purely inline "return [...arrayToCopy, lastItem]" will stick around as long as you have a variable pointing to it. This now has me wondering about closures - perhaps its possible to have a reference to a closure that has an internal variable that's never used again, but the garbage collector doesn't know that. I'm not 100% sure about these things, so I hope someone else can chime in with a more complete answer!