开发者

java.lang.OutOfMemoryError: bitmap size exceeds VM budget - android - how many images? [duplicate]

开发者 https://www.devze.com 2022-12-15 05:00 出处:网络
This question already has answers here: java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android
This question already has answers here: java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android (13 answers) Closed 3 months ago.

I am developing an android app and as I read all around and learned for myself, I cant have a lot of images on the screen at the same time or I will get an exception.

The question is how many images or how many KB in images or how many layouts/images can I have at the same time in the screen.

I know this is not the only thing that has influence on memory, but I am looking for a number so I can plan around it.

Thanks

Daniel


Edit:

I just found this on the android dev site (http://developer.android.com/resources/articles/future-proofing.html)

Technique to Avoid, #3: Going Overboard with Layouts

Due to changes in the View rendering infrastructure, unreasonably deep (more than 10 or so) or broad (more than 30 total) View hierarchies in layouts are now likely to cause crashes. This was always a risk for excessively complex layouts, but you can think of Android 1.5 as being better than 1.1 at exposing this problem. Most developers won't need to worry about this, but if your app has very complicated layouts, you'll need to put it on a diet. You can simplify your layouts using the more advanced layout classes like FrameLayout and TableLayout.

I guess this can be my problem.

开发者_StackOverflow

When it says 'broad' , is it saying on the last level ?

Thanks

Daniel


This answer has 2 parts

1) its not how much images the screen has, but being carefull on cleaning everything up when finishing the activity

2) (Future-Proofing Your App)

Technique to Avoid, #3: Going Overboard with Layouts

Due to changes in the View rendering infrastructure, unreasonably deep (more than 10 or so) or broad (more than 30 total) View hierarchies in layouts are now likely to cause crashes. This was always a risk for excessively complex layouts, but you can think of Android 1.5 as being better than 1.1 at exposing this problem. Most developers won't need to worry about this, but if your app has very complicated layouts, you'll need to put it on a diet. You can simplify your layouts using the more advanced layout classes like FrameLayout and TableLayout.

Daniel


The amount of memory varies from device to device and the amount you have to play with depends on what else the system is doing at the time. Your best bet is to not even come close to running the system out of memory if you can help it. What are you doing that you need that many images on the screen?


This thing is depends on the HEAP size of phone . so if your application acquire more heap then phone provided then it may be create a problem .

the new generation android device contain .here is the list of some

HTC Wildfire (2.2.1) = 16MB.
HTC Wildfire S (2.3.5) = 20MB.
HTC Salsa (2.3.3) = 20MB.
HTC Desire (2.3.3) = 32MB.
HTC Desire S (2.3.5) = 32MB.
Samsung Galaxy S GT-I9000 (2.2) = 48MB.
Samsung Galaxy R GT-I9103 (2.3.5) = 64MB.
Samsung Galaxy Y GT-S5360 (2.3.5) = 64MB

so there is not certan solution for it , but you can try to optimize the the bitmap size . for example recycle the bitmap after use it . or make another using bitmapFectory deoeed from sampleSize .

IF you are using a emulator then you can create a device which contain more heap size to Add new extra hardware configure in your avd manager as VM heap size = 32 or up .

0

精彩评论

暂无评论...
验证码 换一张
取 消