Detecting and Solving Memory Problems in NET, C#
[ Pobierz całość w formacie PDF ]
//-->Detecting and Solving Memory Problems in.NETAlexey TotinThis book is for sale athttp://leanpub.com/detectingandsolvingmemoryproblemsinnetThis version was published on 2016-04-04JetBrains - World’s Leading Vendor of Professional Development ToolsWe help developers work faster by automating common, repetitive tasks to enable them to stayfocused on code design and the big picture. We provide tools to explore and familiarize with codebases faster. Our products make it easy for you to take care of quality during all stages ofdevelopment and spend less time on maintenance tasks.Our JetBrains Technical Series of books focuses on general computer science topics as well astooling.© 2016 Copyright 2000-2016, JetBrainsContentsJetBrains Technical Series. .About This Book . . . . . .How the Book Is OrganizedAcknowledgements . . . .........................................................................................................................................1111233456779111120232525293355565761637072About the Author. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Why Should I Care about Memory?. . . . . . . . .Types of Memory Issues . . . . . . . . . . . . . .How Can I Find These Issues? . . . . . . . . . . .What Does Memory Profiling Look Like Exactly?........................................................................................What Tools Do I Need?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Memory Leaks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .How .NET Stores Objects in Memory . . . . . . . . . . . . . . . . . . . . . . .Who Retains the Object? A Common Approach of Detecting Memory Leaks .What If a Leak Is Not Obvious? Automatic Inspections . . . . . . . . . . . . .How to Fight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .What If There Is Nothing Suspicious in the Object’s Retention Path? GC RootsSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .High Memory Traffic. . . . . . . . . . . . . . . . .How Garbage Collection Works . . . . . . . . . .Considerations on Fighting High Memory TrafficThings Worth Looking For . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . .Ineffective Memory Usage. . . . . . . . . . .Who Retains Memory? . . . . . . . . . . .What Methods Allocate the Most Memory?Things Worth Looking For . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . ......................................................................................................................................................................................................................................................................................Memory Profiling in Unit Tests. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .CONTENTSHow It Works . . . . . . . . . . . . . . . . . . . . . . . . . .When to Use dotMemory Unit . . . . . . . . . . . . . . . . .Example 1. Checking for Specific Objects . . . . . . . . . . .Example 2. Selecting Objects by a Number of Conditions . . .Example 3. Checking Memory Traffic . . . . . . . . . . . . .Example 4. Complex Scenarios for Checking Memory Traffic .Example 4: Comparing Snapshots . . . . . . . . . . . . . . . ..........................................................................................................7273737475757677788282Memory Profiling in Continuous Integration. . . . . . . . . . . . . . . . . . . . . . . . .Integration with JetBrains TeamCity . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Conclusion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .dotMemory and dotTrace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .JetBrains Technical SeriesThis book is a part of theJetBrains Technical Seriesof books covering a wide range of topics relatedto Software Development. For more information on JetBrains, please visitJetBrains website¹.About This BookStrictly speaking, the content of this book is mostly a compilation of a number of blog posts relatedto .NET memory management fromJetBrains ReSharper blog².We had been publishing these postsfor the last two years until we realized that it would be great to put all this material in order. Theresult of such an attempt is this book.The content is based on the experience we’ve had here at JetBrains when developing such well-known products as ReSharper, dotCover, dotTrace, dotMemory and others. In other words, this bookis our vision of best practices in finding and solving memory issues in .NET applications.We hope this book will be useful to a wide range of developers interested in application optimization.For those who’re only starting their way with .NET, this book can be an especially valuable read asit gives short insights on how .NET works “under the hood.”How the Book Is OrganizedEach chapter is devoted to a specific kind of memory issue³, and each subsection features a particularproblem and its solution. This means you can start reading the book from any point. Nevertheless,if you are new to .NET and the topics, we recommend following the book chapter by chapter. Everychapter is prefaced with some theory on .NET memory management, but not so much as to boreyou to death (at least we hope so).AcknowledgementsThe author would like to specially thank Serjic Shkredov, Maarten Balliauw, Ed Pavlov, Fedor Reznik,Anastasia Goncharova, and Mikhail Kropotov for their help with the content, and Hadi Hariri forthe idea of the book.¹https://www.jetbrains.com²http://blog.jetbrains.com/dotnet/³With the exception of the last two chapters, which come as “bonus” content describing ways to automate the detection of memory issues in unittests and continuous integration.1 [ Pobierz całość w formacie PDF ] |