OutOfMemoryError

All your problems with Audio, Video and Images.

OutOfMemoryError

Postby svebee » Thu Jun 10, 2010 3:25 pm

hello, as I'm beginner in Android I have problem with memory - after only 2-3 minutes I get Force Close and outOfMemory Error.

I have only onCreate (I know, stupid, but I didn't knew for anything else as I started only few weeks ago) and inside I have...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  public void onCreate(Bundle savedInstanceState) {
  3.   super.onCreate(savedInstanceState);
  4.   setContentView(R.layout.main);
  5.  
  6.   many lines of code...manipulating with SQLite databases...
  7.  
  8. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4



inside main XML layout I have many images, small, big (background) and so on...How can I on every onCreate "delete" all content from memory that was before in it - so when I open activity again, it deletes all images and everything out and insert the new (old) one inside. "Little" awkward but that's only thing I have on mind.

Also, inside "many lines of code" I don't declare any images!

Or simply, how can I "bypass" outOfMemoryError? Do I have to do something like this (which isn't working as I tested it)?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  @Override
  2.      public void onCreate(Bundle savedInstanceState) {
  3.       super.onCreate(savedInstanceState);
  4.  
  5.         BitmapFactory.Options options=new BitmapFactory.Options();
  6.         options.inSampleSize = 8;
  7.         Bitmap buildingBitmap = BitmapFactory.decodeResource(null,R.drawable.background,options);
  8.  
  9. if (buildingBitmap != null)
  10.         {
  11.         buildingBitmap.recycle();
  12.         System.gc();
  13.         buildingBitmap = null;
  14.         }
  15.  
  16.       setContentView(R.layout.main);
  17.  
  18.       many lines of code...manipulating with SQLite databases...
  19.  
  20.     }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


or...? Also on other activity is everything "the same" except I have multiple overlays, how can I "erase" (recycle) them also? Thank you for any help.

*currently, I'm not searching for fastest, most "correct" or better solution, I just want something that it's not crashing all the time
svebee
Junior Developer
Junior Developer
 
Posts: 21
Joined: Wed Apr 21, 2010 10:19 pm

Top

Re: OutOfMemoryError

Postby uncre8d1 » Thu Jun 10, 2010 5:03 pm

1) If your xml declares images, then they are taking up memory whether or not you define them in your java. Also remember that users tend to prefer an uncluttered interface - all these images may be pretty, but I know from experience that most people don't like to use a program that forces them to hunt for buttons among all the graphics. Maybe your app requires all the images, I don't know - but if not you should consider streamlining this area.

2) You need to find a way to break up your app into activities. Then you can do one thing while your other functions are on hold - this will reduce memory load.

Anyone Else?
Normal?!? Man, I'd give my left arms to be normal.
User avatar
uncre8d1
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Mar 16, 2010 3:41 am
Location: Silver Spring, MD

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 11 guests