.NET GC FAQ
.NET GC FAQ
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.
Table of Contents
- 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
AppDomain
vsAssemblyLoadContext
?
-
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
null
make 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?
-
5.24 Why
GC.Collect
calls 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?
-
5.38 Why
gc.cpp
file 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
ArrayPool
in 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
- Notes
Authors have earned$10,250,807writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
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.
Learn more about Leanpub's ebook formats and where to read them
Top Books
500 QUIZ MMG COMMENTATI
ALS Medicina Generale500 Quiz degli ULTIMI Concorsi di Medicina Generale (2014/2016/2017/2018/2019)
Riassunti e suddivisi per area con Griglia risposte vuota e Griglia risposte esatte Ministeriale
Commentati con link alla fonte per approfondimento e ausilio allo studio
C++20
Rainer GrimmC++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
Functional Design and Architecture
Alexander GraninSoftware Design in Functional Programming, Design Patterns and Practices, Methodologies and Application Architectures. How to build real software in Haskell with less efforts and low risks. The first complete source of knowledge.
Atomic Kotlin
Bruce Eckel and Svetlana IsakovaFor both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Algebra-Driven Design
Sandy MaguireA how-to field guide on building leak-free abstractions and algebraically designing real-world applications.
Thinking with Types
Sandy MaguireThis book aims to be the comprehensive manual for type-level programming. It's about getting you from here to there---from a competent Haskell programmer to one who convinces the compiler to do their work for them.
C++ Best Practices
Jason TurnerLevel up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Stratospheric
Tom Hombergs, Björn Wilmsmann, and Philip RiecksFrom Zero to Production with Spring Boot and AWS. All you need to know to get a Spring Boot application into production with AWS. No previous AWS knowledge required.
Top Bundles
- #1
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #4
Cloud Architect: Transform Technology and Organization
2 Books
Architects don't just recite product names and features. They understand the options, decisions, and trade-offs behind them. They earn credibility and maintain authenticity by connecting the penthouse with the engine room. Get two essential books that redefine the role of the software and IT architect at one low price:37 Things One Architect... - #6
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité... - #7
The Python Craftsman
3 Books
The Python Craftsman series comprises The Python Apprentice, The Python Journeyman, and The Python Master. The first book is primarily suitable for for programmers with some experience of programming in another language. If you don't have any experience with programming this book may be a bit daunting. You'll be learning not just a programming... - #10
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon...