android – 如何找到创建字节数组的源代码

使用DDMS并创建HPROF我可以在我的应用程序中看到数据的“直方图”视图,并注意到过多的非常大的“byte []”对象.我怀疑这是我的代码中的错误或其他愚蠢的结果.但我不知道如何查看这些字节对象的名称或查看源代码中创建它们的位置.可以这样做吗?

解决方法:

看看这里:DDMS Object Allocation Tracking
它逐步指定如何跟踪对象分配并找到对其负责的代码行.

Tracking memory allocation of objects

DDMS provides a feature to track objects that are being allocated to memory and to see which classes and threads are allocating the objects. This allows you to track, in real time, where objects are being allocated when you perform certain actions in your application. This information is valuable for assessing memory usage that can affect application performance.

To track memory allocation of objects:

  • In the Devices tab, select the process that you want to enable allocation tracking for.
  • In the Allocation Tracker tab, click the Start Tracking button to begin allocation tracking. At this point, anything you do in your application will be tracked.

  • Click Get Allocations to see a list of objects that have been allocated since you clicked on the Start Tracking button. You can click on Get Allocations again to append to the list new objects that that have been allocated.

  • To stop tracking or to clear the data and start over, click the Stop Tracking button.
  • Click on a specific row in the list to see more detailed information such as the method and line number of the code that allocated the object.
上一篇:java – Android设备监视器无法从Android Studio或终端启动 – 不支持的major.minor版本52.0


下一篇:Android调试/运行配置