1page.title=Debugging Native Memory Use 2@jd:body 3 4<!-- 5 Copyright 2013 The Android Open Source Project 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18--> 19<p>This tip assume that you are working with an eng 20or userdebug build of the platform, not on a production device.</p> 21<p>Android's native memory allocator has some useful debugging features. You 22can turn on memory tracking with:</p> 23<pre><code> $ adb shell setprop libc.debug.malloc 1 24 $ adb shell stop 25 $ adb shell start 26</code></pre> 27<p>You need to restart the runtime so that zygote and all processes launched from 28it are restarted with the property set. Now all Dalvik processes have memory 29tracking turned on. You can look at these with DDMS, but first you need to 30turn on its native memory UI:</p> 31<ul> 32<li>Open ~/.android/ddms.cfg</li> 33<li>Add a line "native=true"</li> 34</ul> 35<p>Upon relaunching DDMS and selecting a process, you can switch to the new 36native allocation tab and populate it with a list of allocations. This is 37especially useful for debugging memory leaks.</p> 38