我怎么可以强制内存pressure为Android调试? [英] How can I force memory pressure for Android debugging?

查看:114
本文介绍了我怎么可以强制内存pressure为Android调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得在一些问题上我的Andr​​oid应用程序是有,我认为是与内存pressure当我明确的前台模式(Service.startForeground)正在运行的句柄。

I am trying to get a handle on some issues my Android app is having which I think are related to memory pressure when I am running in explicit "foreground" mode (Service.startForeground).

为了调试这个我需要发挥内存pressure在我的应用程序,我可以以不同的方式做到这一点,如启动各种其他应用程序,例如Firefox,有很多网页。然而,这是不太理想的,因为它仍然是相当费时和不精确。所以我的问题是,有没有办法使用调试器(如Eclipse中)或者一个特殊的应用程序专门为此,迫使内存pressure?我宁愿不绕道写一个自己,显然是行不通的,只是在我自己的应用程序分配内存。

In order to debug this I need to exert memory pressure on my app, and I can do this in various ways such as started various other apps such as Firefox with lots of web pages. However this is less than ideal as it still is rather time consuming and inexact. So my question is, is there a way to force memory pressure using the debugger (e.g. under Eclipse) or perhaps a special app specifically for this purpose? I would rather not detour to write one myself, and obviously it won't work to just allocate memory in my own app.

更新:为改变标题反映,我需要在设备上实际的内存pressure,而不是模拟。

Update: changed title for reflect that I need actual memory pressure on a device, not in emulation.

推荐答案

创建一个人造记忆pressure ...

Create an artificial memory pressure...

为您的主要活动的一个按钮,并在其的onclick方法,创造0F 1000对象的数组。虽然您的应用程序正在运行,单击该按钮无数次,应创建内存pressure很多

Create a button for your main activity, and in its onclick method, create an array 0f 1000 Objects. And while your app is running, click that button numerous times which should create alot of memory pressure

所以,code应该是这样的:

So code should look like this:

public void igotclicked(View view){
String[] strings = new String[1000];
}

(假设你定义按钮XML的onclick名)

(assuming that you defined buttons onclick name in xml)

这篇关于我怎么可以强制内存pressure为Android调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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