dotMemory 4what's
insideMaarten BalliauwTechnical [email protected] @maartenballiauw
Who am I? Maarten Balliauw
Belgium (Antwerp)
Technical Evangelist, JetBrains
Focus on web ASP.NET MVC, Windows Azure, ... PHP, ...
Big passion: Cloud (Windows Azure)
Home brewer
http://blog.maartenballiauw.be
@maartenballiauw
Have a question? Use the Question Pane. We’ll try and answer as we go along
Recording
Recording will start now….
Agenda Why use a tool like dotMemory?
What happened to dotTrace Memory?
.NET Memory Management 101
Exploring dotMemory UI concepts Finding a memory leak Analyzing memory traffic
Why use a tool like dotMemory? .NET creates numerous objects in memory, even for simple programs
Memory is constantly being assigned and released (memory traffic)
What if some memory is retained while we expected it to be released?
Why use a tool like dotMemory? dotMemory tries to answer: Why is this object still in memory? What causes the memory leak? What takes so much memory? How much memory traffic is going on? Are there any memory allocation/distribution patterns violated? E.g. event handlers not being unregistered, sparse arrays, …
Don’t just use it when things go wrong!
What does dotMemory do for me? Collect memory snapshot information Info about all objects on the managed heap at the moment a
snapshot is taken
Collect memory traffic information How much memory is allocated / released
Analyze these during a profiling session
What happened to dotTrace Memory? Did you even know we had a memory profiler before? dotTrace Memory 3.5 Hasn’t had any significant updates since 2010 Complex to work with
Time for a fresh memory profiler: dotMemory 4! Friendly – new UI displays complex information in an easy way Powerful – works on very large programs (we use it on R#)
.NET Memory Management 101 Memory Allocation .NET runtime reserves region of address space for every new process managed heap Objects are allocated in the heap Allocating memory is fast, it’s just adding a pointer Some unmanaged memory is also consumed (not GC-ed) .NET CLR, Dynamic libraries, Graphics buffer, …
Memory Release or “Garbage Collection” (GC)
Generations
Large Object Heap
See http://confluence.jetbrains.com/display/NETCOM/What+You+Should+Know+about+.NET+Memory+Management
.NET Memory Management 101 Memory Allocation
Memory Release or “Garbage Collection” (GC) GC releases objects no longer in use by examining application roots GC builds a graph that contains all the objects that are reachable from
these roots. Object unreachable? GC removes the object from the heap, releasing
memory After the object is removed, GC compacts reachable objects in memory.
Generations
Large Object Heap
See http://confluence.jetbrains.com/display/NETCOM/What+You+Should+Know+about+.NET+Memory+Management
.NET Memory Management 101 Memory Allocation
Memory Release or “Garbage Collection” (GC)
Generations Managed heap divided in segments: generation 0, 1 and 2 New objects go into Gen 0 Gen 0 full? Perform GC and promote all reachable objects to Gen 1. This is typically
pretty fast. Gen 1 full? Perform GC on Gen 1 and Gen 0. Promote all reachable objects to Gen 2. Gen 2 full? Perform full GC (2, 1, 0). If not enough memory for new allocations,
throws OutOfMemoryException Full GC has performance impact since all objects in managed heap are verified.
Large Object Heap
See http://confluence.jetbrains.com/display/NETCOM/What+You+Should+Know+about+.NET+Memory+Management
.NET Memory Management 101 Memory Allocation
Memory Release or “Garbage Collection” (GC)
Generations
Large Object Heap
See http://confluence.jetbrains.com/display/NETCOM/What+You+Should+Know+about+.NET+Memory+Management
Generation 0 Generation 1 Generation 2
Short-lived objects (e.g. Local variables)
In-between objects Long-lived objects (e.g. App’s main form)
.NET Memory Management 101 Memory Allocation
Memory Release or “Garbage Collection” (GC)
Generations
Large Object Heap Large objects (>85KB) stored in separate segment of managed
heap: Large Object Heap (LOH) Objects in LOH collected only during full garbage collection Survived objects in LOH are not compacted (by default). This means
that LOH becomes fragmented over time. Fragmentation can cause OutOfMemoryException
See http://confluence.jetbrains.com/display/NETCOM/What+You+Should+Know+about+.NET+Memory+Management
dem
o
Exploring the UIA look at dotMemory 4
The general idea
dem
o
Investigating a memory leakLet’s see if we can find what’s wrong!
What just happened?DispatcherTimer
[]
AdWindow
DispatcherTimer
.Tick
public AdWindow(Window owner){ // ... // Run the timer that changes the ad's image adTimer = new DispatcherTimer(); adTimer.Interval = TimeSpan.FromSeconds(3); adTimer.Tick += ChangeAds; adTimer.Start();}
adTimer.Tick -= ChangeAds;
dem
o
Analyzingmemory trafficHow is the GC affecting our application?
What just happened?for (int i = 0; i <
....
StringReverser
StringReverser
StringReverser
Why use a tool like dotMemory? Why is this object still in memory?
What takes so much memory?
How much memory traffic is going on?
Are there any memory allocation/distribution patterns violated?
Questions
Me, having a question
Resources Try dotMemory 4 now! http://
confluence.jetbrains.com/display/NetProf/dotMemory+4.0+EAP Give us feedback!
Tutorials dotMemory Manual http://bit.ly/dotmemory-manual Getting started http://bit.ly/dotmemory-gettingstarted Finding memory leaks http://bit.ly/dotmemory-findingmemleak Analyzing memory traffic http://bit.ly/dotmemory-memorytraffic
More info
Home
FeedbackVideosBlog
http://jetbrains.com/dottrace
[email protected]://youtrack.jetbrains.com/
issues/DMRYhttp://www.youtube.com/
jetbrainstv.NET Tools Channelhttp://blog.jetbrains.com/dotnet
Thank you for joining us!
Want to learn more?
Follow @dottrace on Twitter
to learn product tips and register for upcoming
webinars
Top Related