Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old January 13th, 2013, 06:57 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Dec 2012
Posts: 9
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Angry Out of Memory Issue

I am calling 'setBackgroundResource' on some png files, which are in the res/drawable-mdpi folder, but not in the other folders.

But after a few back and forward loads the phone runs out of memory.
Any way to clear the memory so I can load the new graphics.

[HIGH]String map_up_theme_res = CoreFunctions.mapThemeRes("up");
String map_down_theme_res = CoreFunctions.mapThemeRes("down");
String service_up_theme_res = CoreFunctions.serviceThemeRes("up");
String service_down_theme_res = CoreFunctions.serviceThemeRes("down");
try {
townUpMap.setBackgroundResource(CoreFunctions.getR esId(
map_up_theme_res, R.drawable.class));
townDownMap.setBackgroundResource(CoreFunctions.ge tResId(
map_down_theme_res, R.drawable.class));
serviceUpTray.setBackgroundResource(CoreFunctions. getResId(
service_up_theme_res, R.drawable.class));
serviceDownTray.setBackgroundResource(CoreFunction s.getResId(
service_down_theme_res, R.drawable.class));
} catch (OutOfMemoryError E) {

}[/HIGH]

pinkfloydim is offline  
Last edited by pinkfloydim; January 13th, 2013 at 04:16 PM.
Reply With Quote
sponsored links
Old January 13th, 2013, 09:40 AM   #2 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,936
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 478 Times in 292 Posts
Default Re: Out of Memory Issue

http://developer.android.com/reference/android/graphics/Bitmap.html#recycle()
__________________
My blog, Inverted Keystrokes, is looking for aspiring developers (not necessarily with Android) to post articles. If you have any development experience and are interested in participating, please PM me. =)
jonbonazza is offline  
Reply With Quote
Old January 13th, 2013, 04:18 PM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Dec 2012
Posts: 9
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

So how do I use this in respect to my code, as just passing in a resource id. How do I get the Bitmap resource in order to recycle it.
pinkfloydim is offline  
Reply With Quote
Old January 14th, 2013, 05:05 AM   #4 (permalink)
Junior Member
 
Join Date: Mar 2010
Location: Santa Monica, CA
Gender: Male
Posts: 31
 
Device(s): Motorola Droid, Archos 5 IT, Motorola Atrix, 46" Sony Google TV, Nexus S, Galaxy Nexus
Carrier: Verizon, AT&T

Thanks: 29
Thanked 1 Time in 1 Post
jungajuice
Default

You really shouldn't, the system should take care of it. You should really only recycle bitmaps when you're iterating through a lot of them.

Chances are you're leaking memory somewhere else that's adding up, and this is just where's its crashing. Make sure you're not holding onto static references of resource intensive objects like Activities.
__________________
@andymcsherry
Andy McSherry | Android Blog
Android App Reiews
jungajuice is offline  
Reply With Quote
Old January 20th, 2013, 04:41 PM   #5 (permalink)
New Member
Thread Author (OP)
 
Join Date: Dec 2012
Posts: 9
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Cool

Every Time I open an activity I am using this code:

[HIGH]final Intent intent = new Intent(cnt, myClass);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
cnt.startActivity(intent);[/HIGH]I am assuming that this clears the activity stack, which should free up memory?
pinkfloydim is offline  
Reply With Quote
Old January 28th, 2013, 11:05 AM   #6 (permalink)
New Member
 
Join Date: Jan 2013
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

You might also consider to optimize your images in order to make them take as little memory as possible when loaded by the app. Image dimensions matter, transparency matters. I blogged about this subject in this blog post
CaptainConnect is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 04:41 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.