Understanding .NET C# Heaps (Deep Dive)

  Рет қаралды 12,069

Raw Coding

Raw Coding

Күн бұрын

A deep dive in to the .net heap structure, understanding heap generations, where objects are allocated in the heap, how objects move across generations and how to leverage this information to your advantage.
Patreon 🤝 / raw_coding
Courses 📚 learning.raw-coding.dev
Shop 🛒 shop.raw-coding.dev
Discord 💬 / discord
Twitter 📣 / anton_t0shik
Twitch 🎥 / raw_coding
🕰 Timestamps
00:00 Introduction
00:50 heap visualisation
08:18 moving objects between generations
13:48 allocating / promoting / sweeping / compacting
17:45 objects array tipping point
20:20 list array tipping point
24:40 performance metrics
27:53 the end
#dotnet #csharp #heap

Пікірлер: 36
@dwhxyz
@dwhxyz Жыл бұрын
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.
@RawCoding
@RawCoding Жыл бұрын
thank you for sharing
@MrJonnis13
@MrJonnis13 Жыл бұрын
Just bought without second thought. I am sure that there is great content inside. Thank you Anton
@RawCoding
@RawCoding Жыл бұрын
thank you, I really appreciate it!
@marcellusfarias5480
@marcellusfarias5480 4 ай бұрын
Always great videos, Anton! I appreciate the level of details you go into your explanations. Hard to find it on the web.
@m-xeas
@m-xeas Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
@@m-xeas And is the content still relevant when it comes to coreCLR ?
@s0weer
@s0weer Жыл бұрын
More content like this, thanks. Tired of newbie shit all over the place
@RawCoding
@RawCoding Жыл бұрын
aye aye chief
@s0weer
@s0weer Жыл бұрын
@@RawCoding thx a lot :)
@TheNorthRemember
@TheNorthRemember 4 ай бұрын
thank you@@RawCoding
@ivandrofly
@ivandrofly Жыл бұрын
Thank you
@bakbak_babble
@bakbak_babble Жыл бұрын
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
@TheNorthRemember
@TheNorthRemember 4 ай бұрын
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 4 ай бұрын
Make your code readable and compressible
@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
@sergeys5270
@sergeys5270 Жыл бұрын
oh, nice!
@minhnguyenkha867
@minhnguyenkha867 Жыл бұрын
Appreciate your effort. I think it's better if you can share reference source
@RawCoding
@RawCoding Жыл бұрын
you can get the source code if you support me on patreon.
@danspark
@danspark Жыл бұрын
Doesn't the unmanaged memory go away if you click the legend? That would make visualization better
@RawCoding
@RawCoding Жыл бұрын
don't know
@RoyZASTEROiD
@RoyZASTEROiD Жыл бұрын
@@RawCoding can you make video about what is garbage collector and how works?
@ManderO9
@ManderO9 Жыл бұрын
my g stopped using console apps for demos and replaced them with minimal APIs
@RawCoding
@RawCoding Жыл бұрын
minimal apis are console apps with extra steps :D
@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
@RoyZASTEROiD
@RoyZASTEROiD Жыл бұрын
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 Жыл бұрын
@@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
@nunyabuziness2700
@nunyabuziness2700 Жыл бұрын
FORST!!!! 💋💋💋
Introduction to Plugin Architecture in C#
21:26
Raw Coding
Рет қаралды 21 М.
C# Channels Explained (System.Threading.Channels)
47:11
Raw Coding
Рет қаралды 35 М.
ONE MORE SUBSCRIBER FOR 6 MILLION!
00:38
Horror Skunx
Рет қаралды 15 МЛН
C# Fundamentals - Stack, Heap, and References
30:42
Rainer Stropek
Рет қаралды 2,1 М.
"Stop Using Async Await in .NET to Save Threads" | Code Cop #018
14:05
Garbage Collection (Mark & Sweep) - Computerphile
16:22
Computerphile
Рет қаралды 233 М.
.NET Core Garbage Collection
14:54
Coding Tutorials
Рет қаралды 21 М.
C# Async/Await/Task Explained (Deep Dive)
24:22
Raw Coding
Рет қаралды 384 М.
Diagnosing memory leaks in .NET apps
37:32
dotnet
Рет қаралды 32 М.
C# Events События
14:36
codaza
Рет қаралды 48 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 595 М.
Avoid this hidden memory allocation in C#
12:38
Raw Coding
Рет қаралды 6 М.