26
dotMemory 4 what's inside Maarten Balliauw Technical Evangelist [email protected] @ maartenballiauw

dotMemory 4 - What's inside?

Embed Size (px)

DESCRIPTION

Even if your program is just a few lines of code, .NET's runtime will create a number of object in memory. Are all objects being destroyed by the garbage collector? Or is there a potential memory leak? And why is the application seemingly slow when having lots of objects in memory? In this webinar, we'll explore the new dotMemory 4 memory profiler. We'll see why we want to use a memory profiler and how easy it is to use JetBrains dotMemory for that.

Citation preview

Page 1: dotMemory 4 - What's inside?

dotMemory 4what's

insideMaarten BalliauwTechnical [email protected] @maartenballiauw

Page 2: dotMemory 4 - What's inside?

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

Page 3: dotMemory 4 - What's inside?

Have a question? Use the Question Pane. We’ll try and answer as we go along

Page 4: dotMemory 4 - What's inside?

Recording

Recording will start now….

Page 5: dotMemory 4 - What's inside?

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

Page 6: dotMemory 4 - What's inside?

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?

Page 7: dotMemory 4 - What's inside?

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!

Page 8: dotMemory 4 - What's inside?

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

Page 9: dotMemory 4 - What's inside?

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#)

Page 10: dotMemory 4 - What's inside?

.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

Page 11: dotMemory 4 - What's inside?

.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

Page 12: dotMemory 4 - What's inside?

.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

Page 13: dotMemory 4 - What's inside?

.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)

Page 14: dotMemory 4 - What's inside?

.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

Page 15: dotMemory 4 - What's inside?

dem

o

Exploring the UIA look at dotMemory 4

Page 16: dotMemory 4 - What's inside?

The general idea

Page 17: dotMemory 4 - What's inside?

dem

o

Investigating a memory leakLet’s see if we can find what’s wrong!

Page 18: dotMemory 4 - What's inside?

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;

Page 19: dotMemory 4 - What's inside?

dem

o

Analyzingmemory trafficHow is the GC affecting our application?

Page 20: dotMemory 4 - What's inside?

What just happened?for (int i = 0; i <

....

StringReverser

StringReverser

StringReverser

Page 21: dotMemory 4 - What's inside?

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?

Page 22: dotMemory 4 - What's inside?

Questions

Me, having a question

Page 23: dotMemory 4 - What's inside?

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

Page 24: dotMemory 4 - What's inside?

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

Page 25: dotMemory 4 - What's inside?

Thank you for joining us!

Want to learn more?

Follow @dottrace on Twitter

to learn product tips and register for upcoming

webinars

Page 26: dotMemory 4 - What's inside?