.NET GC FAQ
This book is 3% complete
Last updated on 2020-04-09
About the Book
Note: This is in progress book, with a rough list of questions to be answered in the final version. The minimum price will be raised when the book is finished. Estimated arrival time is Fall 2020.
The topic of .NET memory management can be seen as quite simple because everything there is automatic and managed by the Garbage Collector. And that's true for most cases. Still, there are some more boundary cases when the convenient abstraction of the GC may become problematic. For example:
- do you know there can be a memory leak in the managed .NET application?
- do you know that your application may be in over 80% busy by doing the GC, not its original work?
- do you know why we should avoid finalizers?
- do you know what are the common cases of allocations?
This book provides a wide variety of questions and answers like the above. It is obviously not as comprehensive as the author's original Pro .NET Memory Management book. Instead, it complements and extends Pro .NET Memory Management, by providing a summary of various topics, while also mentioning some not covered in the original book.
- 1 Introduction
2 General questions
- 2.1 What does XY problem mean?
3 Memory management
- 3.1 What is the memory consumption of my program?
- 3.2 What is the difference between the heap and the stack?
- 3.3 Does big memory consumption of a process slows it down?
- 3.4 When access violation may happen in regular .NET application?
- 3.5 Memory is cheap! Why should I care about its usage then?!
- 3.6 How fast is .NET in terms of memory management performance comparing to native?
- 3.7 What does matter more - memory consumption or memory access?
- 3.8 How to handle large amount of data?
- 3.9 Assembly management (unloading)
- 3.10 How often are the OS memory allocation routines invoked?
- 3.11 IIS - is garbage collection shared between app pools?!
- 3.12 Why does memory go down after I take a heap dump?
- 3.13 What is the one thing that you wish you knew about GC and/or memory in .NET when you were starting your .NET journey?
4 Objects and Allocations
- 4.1 What is the smallest object size possible?
- 4.2 What is the biggest object size possible?
- 4.3 Does memory object layout matter?
- 4.4 Is there any difference between LOH and SOH allocation?
- 4.5 Why arrays of doubles are allocated in Large Object Heap?
- 4.6 I’ve heard allocations are cheap in .NET? If so, why they should be avoided?
- 4.7 What is string interning?
- 4.8 Is it possible to take an address of an object?
4.9 How statics and ThreadStatic are handled in
5 Garbage Collection
- 5.1 When GC kicks in? How often it happens? How long it takes?
- 5.2 How the GC works in .NET and how it knows what to delete?
- 5.3 Do reference cycles slow down GC or affect memory/performance?
- 5.4 Why references may become GC roots?
- 5.5 How does the C# garbage collector find objects whose only reference is an interior pointer?
5.6 Does setting to
nullmake any sense?
- 5.7 What is relation between allocated objects count, allocated memory size and GC pause time?
- 5.8 What will happen if developer try to access an object which is garbage collected?
- 5.9 What is the difference between server-mode GC and the regular one?
- 5.10 What GC mode should I use?
- 5.11 What are default generation sizes?
- 5.12 How quickly an object get promoted to gen 1?
- 5.13 Why does background GC can’t handle gen0 and gen1 collections?
- 5.14 How Foreground GC and Background GC does not interfere on each other?
- 5.15 Why does server mode isn’t the default mode for development environment?
- 5.16 How compaction works in GC?
- 5.17 Why all user threads are suspended for blocking parts of GC in case of Server GC?
- 5.18 How to optimise GC configuration for containers/shared environments?
- 5.19 Can one achieve deterministic pause times in .NET GC?
- 5.20 What are typical memory related problems in .NET?
- 5.21 What is the most important advice related to .NET memory management?
- 5.22 What does the CLR do before throwing an OutOfMemoryException?
- 5.23 How to build a GC friendly cache?
GC.Collectcalls are so discouraged?
- 5.25 What are the optimization tricks that take into account GC and the memory usage in general?
- 5.26 What is pinning?
- 5.27 What is demotion?
- 5.28 Where information about pinning and marking are stored?
- 5.29 Is fragmentation bad or good?
- 5.30 How to avoid fragmentation in SOH? in LOH?
- 5.31 What are card tables and card bundles?
- 5.32 What are write barriers?
- 5.33 Why I notice different behaviour under Debug and Release builds?
- 5.34 Is it possible to check in-process whether GC is happening?
- 5.35 What is the reason for so high % Time in GC values?
- 5.36 Will be there more GC configuration knobs, like in Java HotSpot GC?
- 5.37 Can we replace GC in .NET? Can we modify it?
gc.cppfile in CoreCLR is so huge?
- 5.39 Is there any roadmap for improving GC?
- 5.40 Is .NET GC better than GC in X language/runtime?
- 5.41 How to learn more about GC?
6 Resource management
- 6.1 What is the difference between a managed and unmanaged resource?
- 6.2 Should I implement a finalizer when I implement IDisposable?
- 6.3 When in doubt - Dispose() - Is this always the case?
6.4 Does GC treat any memory available under
ArrayPoolin any special way?
- 6.5 I have a lot of objects in finalization queue. Is it bad?!
- 6.6 Is it possible to have an object not referenced (unreachable) in finalization queue?
- 7 Miscellaneous topics
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.