Getting OutOfMemory error while loading images from file

All your problems with Audio, Video and Images.

Getting OutOfMemory error while loading images from file

Postby valibab » Wed Jan 07, 2009 12:46 pm

Getting OutOfMemory error while loading images from local file
data/data/mypackage/file

i am using these lines of code to get the files

fos = openFileInput(files[i]);
bitmap=BitmapFactory.decodeStream(fos);

614400-byte external allocation too large for this process.
VM won't let us allocate 614400 bytes
xxxxxxxxxxxxxxxxxxxx allocPixelRef failed
Shutting down VM
thread exiting with uncaught exception (group=0x40010e28)
Uncaught handler: thread main exiting due to uncaught exception

java.lang.OutOfMemoryError: bitmap size exceeds VM budget

at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:304)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:328)


i am tring to do bitmap.recycle()
after getting images then i am facing error
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@43462320

please help me to solve this problem

regards
valibab
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Jan 03, 2009 7:11 am

Top

Postby MrSnowflake » Wed Jan 07, 2009 12:57 pm

Why don't you try: BitmapFactory.decodeFile() that would probably be a lot more efficient.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby valibab » Wed Jan 07, 2009 2:38 pm

i have tried with the
bitmap = BitmapFactory.decodeFile("/data/data/mypackage/files/filename", options);

but still getting the same error OutOfMemory
valibab
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Jan 03, 2009 7:11 am

Postby andmol » Thu Jan 22, 2009 12:14 am

I would also suggest to use BitmapFactory.decodeFile() and try to set options.inSampleSize. That will subsample your image and will return a smaller one so it does not need so much memory.

If you want to load a couple of images, try to recycle the old ones to free that memory.
andmol
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Sep 30, 2008 5:34 pm

Postby andreleitao » Mon Sep 14, 2009 3:24 pm

Hi, valibab. Maybe the best solution is to recycle unused bitmaps (as said before), but you must avoid to access these recycled bitmap objects, otherwise you will get the exception you told us:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  java.lang.RuntimeException: Canvas: trying to use a recycled bitmap.
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Recycled bitmaps are totally dead, you must instantiate one more time if you want to use them again.

Once I did have a problem like yours. My app was showing OutOfMemory error frequently. bitmap.recycle() was the solution. :)

Good luck! :D
andreleitao
Experienced Developer
Experienced Developer
 
Posts: 70
Joined: Tue Mar 10, 2009 9:56 pm
Location: Recife - Brazil

Postby saamyandroid » Thu Feb 11, 2010 9:51 am

andreleitao wrote:
Recycled bitmaps are totally dead, you must instantiate one more time if you want to use them again.

Good luck! :D


How to instantiate. Bitmap Dont have Constructor.
saamyandroid
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Sep 09, 2009 8:17 pm
Location: INDIA

Top

Postby azraeal » Fri Feb 12, 2010 7:21 am

saamyandroid wrote:How to instantiate. Bitmap Dont have Constructor.


Read the previous posts. They're literally spelled out for you. And don't quintuple post across boards. It's a sure fire way to be ignored.
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Postby saamyandroid » Thu Feb 18, 2010 7:10 pm

Thanks for your Reply,

But I have not received any solution for this Problem.

Bitmap.recycle()
-----------------

Once we called recycle() on bitmap Object ,After that we cant use that bitmap Object .
So this is a solution. this might be the android bug .

Even though Android is a Rich environment to Develop mobile Application,Android not providing Bitmap garbage Collection.

May i know the heap Size for android application.
is there Separate Memory allocated for Image like SAMSUNG?
saamyandroid
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Sep 09, 2009 8:17 pm
Location: INDIA

Postby azraeal » Thu Feb 18, 2010 7:50 pm

@saamyandroid
valibab wrote:fos = openFileInput(files[i]);
bitmap=BitmapFactory.decodeStream(fos);


MrSnowflake wrote:BitmapFactory.decodeFile()


etc...

Literally, spelled, out. In the first four posts of the tread. Read the thread.
Not every object is instantiated through a public constructor.
There is no bug.

And why are you asking this? You claimed to have recycled the bitmap (in other posts), so you must have had a bitmap in the first place. How did you originally obtain your bitmap? Why can't you have repeated that process?

Heap size is 16MB.
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Postby saamyandroid » Sat Feb 20, 2010 7:01 pm

Hi azraeal ,

Thanks for you reply,

I know these ways to initialise Bitmap Object.
But i got error (Trying to use recycled Bitmap Object).

So only i confused n asked ,how to initialise Object.


I made bit mistake.Recycled while that bitmap object is in use.
Any way i solved that problem.Thank you azraeal .
saamyandroid
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Sep 09, 2009 8:17 pm
Location: INDIA

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 16 guests