.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.
- 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.
C++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.
The book is almost daily updated. These incremental updates ease my interaction with the proofreaders.
A Guide to Artificial Intelligence in HealthcareDr. Bertalan Mesko
Can we stay human in the age of A.I.? To go even further, can we grow in humanity, can we shape a more humane, more equitable and sustainable healthcare? This e-book aims to prepare healthcare and medical professionals for the era of human-machine collaboration. Read our guide to understanding, anticipating and controlling artificial intelligence.
C++ Best PracticesJason Turner
Level up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Atomic KotlinBruce Eckel and Svetlana Isakova
For 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!
Sockets and PipesType Classes
Sockets and Pipes is not an introduction to Haskell; it is an introduction to writing software in Haskell. Using a handful of everyday Haskell libraries, this book walks through reading the HTTP specification and implementing it to create a web server.
Introducing EventStormingAlberto Brandolini
The deepest tutorial and explanation about EventStorming, straight from the inventor.
node-opcua by exampleEtienne Rossignon
Get the best out of node-opcua through a set of documented examples by the author himself that will allow you to create stunning OPCUA Servers or Clients.
Ansible for DevOpsJeff Geerling
Ansible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Functional Design and ArchitectureAlexander Granin
Software 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.
Composing SoftwareEric Elliott
All software design is composition: the act of breaking complex problems down into smaller problems and composing those solutions. Most developers have a limited understanding of compositional techniques. It's time for that to change.
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...
All the Books of The Medical Futurist
6 BooksWe 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...
3 BooksBuy every PowerShell book from Adam Bertram at a 20% discount!
Cisco CCNA 200-301 Complet
4 BooksCe lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301.
Linux Administration Complet
4 BooksCe 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é...
Modern C++ by Nicolai Josuttis
Django for Beginners/APIs/Professionals
Learn Git, Bash, and Terraform the Hard Way
3 BooksLearn Git, Bash and Terraform using the Hard Way method.These technologies are essential tools in the DevOps armoury. These books walk you through their features and subtleties in a simple, gradual way that reinforces learning rather than baffling you with theory.
Software Architecture and Beautiful APIs
2 BooksThere is no better way to learn how to design good APIs than to look at many existing examples, complementing the Software Architecture theory on API design.
Digital Future of Healthcare and Pharma
3 BooksThese three popular e-books from The Medical Futurist describes how digital health technologies will shape the future of health, healthcare, medicine and pharma with exciting infographics in a digestible format.