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