English 中文(简体)
我如何避免在安乐器的图像上留下记忆?
原标题:How do I keep from running out of memory on graphics for an Android app?

我先在Eclipse做一个安乐器,迄今为止,我的方案没有真正增长过以往的中小块。 然而,我已经陷入了记忆错误的 Out。 你们看到,我现在使用的图象完全是该方案的比图和多民族国家,最近,当我试图为该方案增加一点功能时(主要包括几个更多的比图,并造成另外的间谍),它开始在形形形形的构造中坠毁——并大体;间谍构造。 当我追踪这一问题时,它被证明是记忆错误的外表,而这种错误似乎是由于将太多的图像档案添加到该方案中,并从中产生可图的。

这将是一个问题,因为我确实没有看到许多图片资源在该方案中发挥作用。 我甚至开始把声音包括在内。 这些图象都是ancy。 我的问题是:

(1) 是否真正地将安乐电话方案局限在他们能够雇用多少记忆上,或者说这或许是造成这种错误的20-30个资源图象之外的东西?

2) 如果信安的记忆如此之大,它甚至能够处理20-30个图像资源被装入同时存在的可提取资源,那么,在世界上,你应如何为之提供象样的图像和声音?

感谢。

最佳回答

正如Steve和Paul已经提到的那样,关键因素是你的形象如何大。 氯乙烯的应用仅限于标准电话中的16Mb和隐藏电话上的24Mb。 这是一种硬性限制。 这严重限制了您的图表数量。

很容易计算出你的图形尺寸:高血压×高的大小(16或32比)。

一些建议:

  • You need to check your code carefully for memory leaks. It is extremely easy to leak memory in Android, and if you leak a couple of bitmaps a few times, you ll run out of memory fast. This article may help.
  • Always load your graphics using ARGB_4444 (16bit) if at all possible. That alone, can reduce memory consumption for graphics by a factor 2.
  • Always null and recycle resources if you can, to assist the gc.
  • Try to ensure that graphics are only used once. Having a resource handling class that deals with this can be very useful (at least if you re doing games).
问题回答

最容易的方式是,在申请标本中增加这2条线。

android:hardwareAccelerated="false" android:largeHeap="true"

但是,如果你正在建设高效的记忆,就不建议这样做。 但是,这确实行之有效。

Hmm.... 我用一些静态图像(即模拟图像)书写安乐器,这样阅读你的问题就产生了几个问题:

  • 你们使用什么样的环境? 这是否使用SDK的支持者,或者是否用真的电话? 如果你重新担任主人,你可能希望确保用与电话相匹配的光谱来创建电话(即使如此,由于电话的专用硬件,电话的使用可能比电话的要慢)。

  • 你们是否需要同时装满所有可提装备? 例如,如果你重新绘制形象,你在每次抽取时是否都能够打上可图的图象,或者你能否重新利用同样的可图和简单地转播实际呼声的事例?

  • 同样,你能否把他们装上dem子? E.g. 如果你有光灯,你是否只能显示照片1-9,在用户点击下顿后装载照片10-19?

  • 你们的形象是否大? 高密度?

我认识到这些是高层次的,难以适用;我认为,我对你从描述中再次出现问题的想法并不大。 我只打了几个 s子,并且能够节省最多钱,对我(really)需要多少时间才能使用“new 关键词,以及显示和什么是关键词。 我还发现。 业绩优化网页非常有用(主要有游戏,,见

亲爱!

你试图装载的图形大小很重要。 如果小幅(如50x50),你很容易装上几十个轨道地图,但如果每个地图的大小都足以填满屏幕,则你只能做几个以上。 这还取决于你试图与这些形象做些什么。 例如,如果你重新试图顺利地轮流图像90度,甚至大约300x300px就足以使照片几乎死亡。

你们需要做一些事情。

  1. Try not to load images until you need them.
  2. Try to reduce their graphics detail if you can. For example, you can decode bitmaps into RGB 565, ARGB_4444 or ARGB_8888 which each take different amounts of memory. Set this using a BitmapFactory.Options object as a parameter when decoding images.
  3. See if you can cheat - for example, it s easier on memory to take one small image and fill the screen with the image repeated over and over (like tiles), than to use one large image. It s also easier to process an image that s a quarter the size you want it to be, but drawn with a 2x scale factor.
  4. Read this article from the developer of Light Racer and his follow-ups to get some insight into how tweaking performance is one of the most difficult but crucial things to do when developing a game.

记忆泄露和毫无理由地制造可提取产品并不是一个问题,但我提到的是第二个问题。 然而,所有提到的其他事情都是宝贵的信息。 这是我试图制作的录像游戏,因此,从我可以发现的那种不现实的游戏,是不断制造和删除可提取的物品,这要取决于它们是否重新出现在第二位屏幕上;对于 sp,我认为,我需要继续装满负荷,直到这些间谍活动本身被消除,而不仅仅是在屏幕上。 关于这一错误,我基本上只把太多的可提取材料装上在方案启动期间记忆中。

现在我刚才想到的一件事——这是造成这一特别错误的NOT,但会造成类似的错误——是,我正在为每一个间谍创造一系列的灯塔,当时我刚刚注意到,我只应当为各种间谍活动这样做。

我不得不研究将图形缩小到16轨和足迹的准确方法,因为许多申请确实需要ancy。 我认为,我用几天时间监测这一read光,如果其他人有任何其他想法,那么我就把它所回答。 Thanks。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签