Understanding .NET C# Heaps (Deep Dive)

Поделиться
HTML-код
  • Опубликовано: 5 ноя 2024

Комментарии • 36

  • @dwhxyz
    @dwhxyz Год назад +18

    In case anyone wonders why 85,000 was used in the example - from Microsoft docs -> If an object is greater than or equal to 85,000 bytes in size, it's considered a large object. This number was determined by performance tuning. When an object allocation request is for 85,000 or more bytes, the runtime allocates it on the large object heap.

  • @m-xeas
    @m-xeas Год назад +5

    It is worth mentioning, that as J.Richter mentioned in his book "CLR via C#", during GC, objects with deconstructors (finalizers), which no longer have references are placed in a Freachable queue. A special CLR high-priority thread picks up objects from that queue, runs Finalize method (deconstructor), after what marks objects as ready for collection. Next time GC checks for objects from the Freachable queue which were marked as ready for collection and cleans them up. That's why the developer cannot be sure when an object with a deconstructor will be garbage-collected during the next GC

    • @mrwalkan
      @mrwalkan Год назад

      Helpful

    • @codewkarim
      @codewkarim Год назад

      Do you recommend the book? Up til now I avoided reading it but it comes coming up in my career everytime I search for internals.

    • @m-xeas
      @m-xeas Год назад +1

      @@codewkarimI bet you wouldn't regret reading it. The main advantage of this book is that Richter explains CLR using C# as an example, so you will find a lot of "under the hood" stuff.

    • @codewkarim
      @codewkarim Год назад +2

      @@m-xeas And is the content still relevant when it comes to coreCLR ?

  • @MrJonnis13
    @MrJonnis13 Год назад +3

    Just bought without second thought. I am sure that there is great content inside.
    Thank you Anton

    • @RawCoding
      @RawCoding  Год назад +1

      thank you, I really appreciate it!

  • @s0weer
    @s0weer Год назад +10

    More content like this, thanks. Tired of newbie shit all over the place

  • @marcellusfarias5480
    @marcellusfarias5480 9 месяцев назад

    Always great videos, Anton! I appreciate the level of details you go into your explanations. Hard to find it on the web.

  • @TheNorthRemember
    @TheNorthRemember 9 месяцев назад +1

    ok I was sleepy when I watched the vid, but my question is what should we do besides reducing the number of allocations in the code ? what technique we should follow?
    thanks Anton your vids are always grate

    • @RawCoding
      @RawCoding  9 месяцев назад

      Make your code readable and compressible

  • @bakbak_babble
    @bakbak_babble Год назад +4

    It's a very good content nice topic 🤩 .Can we have part 2 related/similar to avoiding object greater than 85 kilo bytes. How to deal with those large LOH object if occured in any scenario?

    • @adrian_franczak
      @adrian_franczak Год назад

      it is not so common to run over 85k in webapi world

  • @adrian_franczak
    @adrian_franczak Год назад

    probably there is an edge case where you use array of struct so the tipping point will be 85k/sizeof(myStruct) - 3

  • @minhnguyenkha867
    @minhnguyenkha867 Год назад +3

    Appreciate your effort.
    I think it's better if you can share reference source

    • @RawCoding
      @RawCoding  Год назад +1

      you can get the source code if you support me on patreon.

  • @ivandrofly
    @ivandrofly Год назад

    Thank you

  • @danspark
    @danspark Год назад +1

    Doesn't the unmanaged memory go away if you click the legend? That would make visualization better

    • @RawCoding
      @RawCoding  Год назад

      don't know

    • @RoyZASTEROiD
      @RoyZASTEROiD Год назад +1

      @@RawCoding can you make video about what is garbage collector and how works?

  • @sergeys5270
    @sergeys5270 Год назад

    oh, nice!

  • @ManderO9
    @ManderO9 Год назад +1

    my g stopped using console apps for demos and replaced them with minimal APIs

    • @RawCoding
      @RawCoding  Год назад +4

      minimal apis are console apps with extra steps :D

  • @RoyZASTEROiD
    @RoyZASTEROiD Год назад +1

    how i know only SOH is seperated to generations, LOH is not seperated to any generation. And how i know - yes, when gen 2 is collected by GC, same time automatically LOH will too collected by GC.

    • @RawCoding
      @RawCoding  Год назад

      What do you mean how you know? That’s how it’s built. LOH is inside gen 2

    • @RoyZASTEROiD
      @RoyZASTEROiD Год назад +1

      @@RawCoding how i know = how i read before. Loh is separated segment from gen2, loh internally kept tracked as gen3. But there are collected at the same time when gen2 is collected by gc. I mean saying that gen2 is seperated to 2 parts loh/soh is not fully truth. There are collected at the same time (when gc was called for gen2) yes, but this not means soh and loh are stored in gen2 or part of gen2.

    • @RawCoding
      @RawCoding  Год назад

      Yes you are right, physically LOH is a separate memory boundary from gen2 memory region. Both are collected as part of gen 2 gc

  • @pedroferreira9234
    @pedroferreira9234 Год назад

    When you gc gen 1, gc is made in gen 0 and when gc runs gen2 gc is also made in 1 & 0

  • @nunyabuziness2700
    @nunyabuziness2700 Год назад

    FORST!!!! 💋💋💋