通过监控我的Andr​​oid应用程序ocuppied内存 [英] Monitor the memory ocuppied by my app in Android

查看:704
本文介绍了通过监控我的Andr​​oid应用程序ocuppied内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯试图优化存储我的应用程序占用量。 当我的应用程序加载(控股home键,然后选择任务管理器),我可以看到应用程序正在17MB,但该值不会刷新。 我如何才能实时跟踪的价值呢? DDMS有一个选项?请具体说明我寻觅了很多,没有什么发现。 在此先感谢

im attempting to optimize the amount of memory my app consumes. When my app loads (holding home key and then selecting task manager) i can see the app is taking 17MB but that value doesn't refresh. How can I track that value in real time? DDMS have a option for that? Please be specific I have searched a lot and nothing found. thanks in advance

推荐答案

另一个更code为导向的调试方法内存跟踪中出现的 http://stackoverflow.com/a/6471227/978329 一个链接到博客有更多的信息。

Another more code-oriented debug method for memory tracking appears in http://stackoverflow.com/a/6471227/978329 with a link to a blog with more info.

要长话短说,你可以仔细把下面的code(或它的一个改进版本)到某种对click事件,并获得实时信息写入日志或举杯消息:

To make it short, you can carefully put the following code (or an improved version of it) into some kind of on click event and get the real-time info into a log or a toast message:

View v = (View) findViewById(R.id.SomeLayout);

    v.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {

            Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
            Debug.getMemoryInfo(memoryInfo);

            String memMessage = String.format("App Memory: Pss=%.2f MB, Private=%.2f MB, Shared=%.2f MB",
                    memoryInfo.getTotalPss() / 1024.0,
                    memoryInfo.getTotalPrivateDirty() / 1024.0,
                    memoryInfo.getTotalSharedDirty() / 1024.0);

            Toast.makeText(ThisActivity.this,
                    memMessage,
                    Toast.LENGTH_LONG).show();
            Log.i("log_tag", memMessage);
        }
        });   

这篇关于通过监控我的Andr​​oid应用程序ocuppied内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆