我正在为一个学校项目开发一个小的tamagotchi,我在应用程序使用的内存量方面存在很大问题。 起初我有200MB分配给应用程序,经过一些研究,我得到一个简单的修复,通过将drawable文件夹重命名为drawable-nodpi将其减少到50MB。 但这仍然是很重要的。 在调查问题的同时,我确信它与我的布局和UI元素有关,因为我删除了所有代码并仅使用布局启动了我的应用程序,内存使用量根本没有下降。
在这里你可以看到我的布局:
图像大小平均大约30kb,如果我计算内存中可能图像的最大大小,我有大约1.5MB。
那么所有的记忆都来自哪里? 这怎么可能呢?
如果你想亲自看看应用程序,你可以从github获取项目: https : //github.com/kruben95/TamaStudent
如果有人可以帮助我或给我一些提示,我会很高兴。
I am developing a small tamagotchi for a school project and I have huge problems with the amount of memory the app is using. At first I had 200MB allocated to the app and after a bit of researching I got a easy fix to reduce it to 50MB by renaming the drawable folder into drawable-nodpi. But this is still way to much. While investigating the problem I'm sure that it has something to do with my Layout and UI-Elements because i deleted all my Code and launched my app only with the Layout and the memory usage didn't drop at all.
Here you can see my Layout:
The image-sizes are in average about 30kb and if I calculate the maximum size of possible images in the memory I have around 1.5MB.
So where does all the memory come from? How is that even possible?
If you want to see the app by yourself you can get the project from github: https://github.com/kruben95/TamaStudent
I would be happy if someone can help me or give me some tips.
最满意答案
我下载了你的项目,这里有一些建议:
1)图像是大分辨率,即使在磁盘上它们需要30-40 kb - 在内存中它们是位图和位图占用大量内存,例如正文部分 - 1200x1980像素,每像素4个字节,这是内存中的9.5兆字节!! ?? 现在在这个位图得到之后它还必须扩展它 - 这是额外的内存,并且如你所见,你只有一个图像有超过10兆字节!! 这非常高。
2)使图像分辨率降低。 没有必要显示它们如此高的分辨率。
3)从图像中删除隐形部分 - 因为我看到非常大的部分是清晰的但它需要记忆!
4)尝试以编程方式制作一些图像,如圆圈等。
5)在代码中 - 如果你只需要做背景,不要使用alpha作为背景,直接用颜色设置这个alpha:#00FFFFFF - 这里是alpha的白色。如果你在视图上使用alpha,它将需要额外的内存重绘(性能较低)。
6)谷歌互联网为您的相关主题与标记Best practices ,你会发现很多有用的信息)
I downloaded your project, and here is some suggestions:
1) images are big resolution even if on disk they take 30-40 kb - in memory they are bitmap and bitmap takes a lot of memory, for example body part - 1200x1980 pixels with 4 bytes per pixel this is 9,5 megabytes in memory!!?? now after this bitmap got it must also scale it - this is additional memory, and as you see you have more then 10 megabytes per only one image!! this is extremely HIGH.
2) make images lower resolution. no need to display them so high res.
3) remove from images invisible parts - as i see very big parts are clear but it takes memory!
4) try to make some images programmatically, like circles etc.
5) in code - don't use alpha for view if you only need to do background, set this alpha directly in color: #00FFFFFF - here is white color with alpha 0. If u use alpha on view it will take additional memory for redrawing (lower performance).
6) google internet for your related topics with tag Best practices and you will find a lot of useful information )
Android应用程序中的高内存使用率(50MB)(High Memory usage in Android Application (50MB))我正在为一个学校项目开发一个小的tamagotchi,我在应用程序使用的内存量方面存在很大问题。 起初我有200MB分配给应用程序,经过一些研究,我得到一个简单的修复,通过将drawable文件夹重命名为drawable-nodpi将其减少到50MB。 但这仍然是很重要的。 在调查问题的同时,我确信它与我的布局和UI元素有关,因为我删除了所有代码并仅使用布局启动了我的应用程序,内存使用量根本没有下降。
在这里你可以看到我的布局:
图像大小平均大约30kb,如果我计算内存中可能图像的最大大小,我有大约1.5MB。
那么所有的记忆都来自哪里? 这怎么可能呢?
如果你想亲自看看应用程序,你可以从github获取项目: https : //github.com/kruben95/TamaStudent
如果有人可以帮助我或给我一些提示,我会很高兴。
I am developing a small tamagotchi for a school project and I have huge problems with the amount of memory the app is using. At first I had 200MB allocated to the app and after a bit of researching I got a easy fix to reduce it to 50MB by renaming the drawable folder into drawable-nodpi. But this is still way to much. While investigating the problem I'm sure that it has something to do with my Layout and UI-Elements because i deleted all my Code and launched my app only with the Layout and the memory usage didn't drop at all.
Here you can see my Layout:
The image-sizes are in average about 30kb and if I calculate the maximum size of possible images in the memory I have around 1.5MB.
So where does all the memory come from? How is that even possible?
If you want to see the app by yourself you can get the project from github: https://github.com/kruben95/TamaStudent
I would be happy if someone can help me or give me some tips.
最满意答案
我下载了你的项目,这里有一些建议:
1)图像是大分辨率,即使在磁盘上它们需要30-40 kb - 在内存中它们是位图和位图占用大量内存,例如正文部分 - 1200x1980像素,每像素4个字节,这是内存中的9.5兆字节!! ?? 现在在这个位图得到之后它还必须扩展它 - 这是额外的内存,并且如你所见,你只有一个图像有超过10兆字节!! 这非常高。
2)使图像分辨率降低。 没有必要显示它们如此高的分辨率。
3)从图像中删除隐形部分 - 因为我看到非常大的部分是清晰的但它需要记忆!
4)尝试以编程方式制作一些图像,如圆圈等。
5)在代码中 - 如果你只需要做背景,不要使用alpha作为背景,直接用颜色设置这个alpha:#00FFFFFF - 这里是alpha的白色。如果你在视图上使用alpha,它将需要额外的内存重绘(性能较低)。
6)谷歌互联网为您的相关主题与标记Best practices ,你会发现很多有用的信息)
I downloaded your project, and here is some suggestions:
1) images are big resolution even if on disk they take 30-40 kb - in memory they are bitmap and bitmap takes a lot of memory, for example body part - 1200x1980 pixels with 4 bytes per pixel this is 9,5 megabytes in memory!!?? now after this bitmap got it must also scale it - this is additional memory, and as you see you have more then 10 megabytes per only one image!! this is extremely HIGH.
2) make images lower resolution. no need to display them so high res.
3) remove from images invisible parts - as i see very big parts are clear but it takes memory!
4) try to make some images programmatically, like circles etc.
5) in code - don't use alpha for view if you only need to do background, set this alpha directly in color: #00FFFFFF - here is white color with alpha 0. If u use alpha on view it will take additional memory for redrawing (lower performance).
6) google internet for your related topics with tag Best practices and you will find a lot of useful information )
发布评论