1page.title=Memory Monitor Walkthrough
2meta.tags="android, performance, profiling, tools, memory, memoryleaks, garbagecollection, memorymonitor"
3page.tags="android", "performance", "profiling", "tools", "memory", "memoryleaks", "garbagecollection", "memorymonitor"
4page.metaDescription=Graph memory usage and garbage collection events for your app in real-time.
5page.image=tools/performance/thumbnails/tools_memory_monitor.png
6page.article=true
7
8@jd:body
9
10<style>
11  .no-bullet {
12    list-style-type: none;
13  }
14  .padded {
15    padding-left: 10px;
16  }
17</style>
18
19<div id="tb" style="margin-left: 7px; margin-bottom: 5px;">
20
21<h2>In this document</h2>
22<ul>
23  <li><a href="#WhatYouNeed">Prerequisites</a></li>
24  <li><a href="#WorkingWithMemoryMonitor">Working with Memory Monitor</a></li>
25</ul>
26
27<h2>You should also read</h2>
28<ul>
29  <li><a href="{@docRoot}tools/performance/heap-viewer/index.html">
30    Heap Viewer Walkthrough</a></li>
31  <li><a href="{@docRoot}tools/performance/allocation-tracker/index.html">
32    Allocation Tracker Walkthrough</a></li>
33  <li><a href="{@docRoot}tools/performance/comparison.html">
34    Comparison: Memory Monitor, Heap Viewer, Allocation Tracker</a>
35  <li><a href="{@docRoot}tools/performance/traceview/index.html">
36    Traceview Walkthrough</a></li>
37</ul>
38
39</div>
40
41
42  <p>This walkthrough shows the basic usage and workflow for the Memory Monitor tool in Android
43  Studio. Memory Monitor reports in real-time how your app allocates memory.</p>
44
45  <p>What it's good for:</p>
46
47  <ul>
48    <li>Showing available and used memory in a graph, and garbage collection events over time.</li>
49
50    <li>Quickly testing whether app slowness might be related
51    to excessive garbage collection events.</li>
52
53    <li>Quickly testing whether app crashes may be related to running out of
54    memory.</li>
55  </ul>
56
57  <h2 id="WhatYouNeed">Prerequisites</h2>
58
59  <ul>
60    <li>A mobile device with <a href=
61    "http://developer.android.com/tools/device.html#developer-device-options">Developer Options</a>
62    enabled.</li>
63
64    <li>An Application with USB Debugging enabled. Use your own, or the <a href=
65    "https://github.com/udacity/Sunshine-Version-2">Sunshine</a> sample app from the <a href=
66    "https://www.udacity.com/course/ud853">Android Fundamentals Udacity course</a>.</li>
67  </ul>
68
69  <h2 id="WorkingWithMemoryMonitor">Working with Memory Monitor</h2>
70
71 <ul class="no-bullet">
72<!-- this also hides bullet, by default outside box -->
73 <li><div style="overflow:hidden">
74  <ol class="padded">
75
76    <div class="figure" style="">
77  <img src="{@docRoot}images/tools/performance/memory-monitor/gettingstarted_image001.png"
78         alt=""
79         width="300px" />
80      <p class="img-caption">
81        <strong>Figure 1. </strong>Starting Memory Monitor.
82      </p>
83    </div>
84
85    <li>If you're using a mobile device, connect it to your computer.</li>
86
87    <li>Open your application in Android Studio, build the source,
88      and run it on your device or emulator.</li>
89
90    <li>In Android Studio, choose <strong> Tools &gt; Android &gt; Memory Monitor</strong>. You
91      can also click the <em>Android</em> tab in the lower-left corner of the application
92      window to launch the Android runtime window. The CPU and Memory Monitor views appear.</li>
93
94 </ol>
95</div></li>
96
97
98<li><div style="overflow:hidden">
99<hr>
100  <ol class="padded" start="7">
101
102    <div class="figure" style="">
103  <img src="{@docRoot}images/tools/performance/memory-monitor/gettingstarted_image003.png"
104         alt=""
105         width="400px" />
106      <p class="img-caption">
107        <strong>Figure 1. </strong>Allocated and free memory in Memory Monitor.
108      </p>
109    </div>
110
111    <li>Once Memory Monitor starts tracking your device, a stacked graph appears,
112      tracking memory usage over time.
113
114      <p>Dark blue: Amount of memory that your app
115      is currently using.</p>
116
117      <p>Light blue: Available, unallocated memory.</p>
118    </li>
119
120    <li>Over time, this graph updates, showing changes in memory usage.</li>
121
122    <li>As your app allocates and frees memory, the allocated amount shown in the
123      graph changes.</li>
124
125    <li>When you see the allocated memory drop by a large amount, a garbage
126      collection (GC) event has occurred.</li>
127
128 </ol>
129</div></li>
130
131<li><div style="overflow:hidden">
132<hr>
133  <ol class="padded" start="11">
134
135    <div class="figure" style="">
136  <img src="{@docRoot}images/tools/performance/memory-monitor/gettingstarted_image005.png"
137         alt=""
138         width="400px" />
139      <p class="img-caption">
140        <strong>Figure 2. </strong>Forcing a GC (Garbage Collection) event.
141      </p>
142    </div>
143
144    <li>You can force a garbage collection event by clicking on the garbage truck
145      icon
146<img src="{@docRoot}images/tools/performance/memory-monitor/gettingstarted_image004.png">.
147    </li>
148
149 </ol>
150</div></li>
151</ul>
152
153
154