Discussion Forums  >  Crashes, Memory Warnings

Replies: 5    Views: 577

Eric F
Lost but trying
Profile
Posts: 13
Reg: Mar 21, 2013
Clovis
3,380
07/02/13 07:08 AM (11 years ago)

This Handler class should be static or leaks might occur

In my project it keeps crashing due to the VM budget being exceed. The pictures that I am using are all very small but supposedly they keep filling up the VM. I was working through eclipse and notice 2 instances where it gave me the following errors. This Handler class should be static or leaks might occur (com.quickreaction.BT_screen_menuButtons.2) BT_screen_menuButtons.java /BT_activity_root/src/com/quickreaction line 1091 Android Lint Problem When I follow the two links this is the source code that it brings me too. Handler downloadScreenDataHandler = new Handler(){ @Override public void handleMessage(Message msg){ if(JSONData.length() < 1){ hideProgress(); showAlert(getString(R.string.errorTitle), getString(R.string.errorDownloadingData)); }else{ parseScreenData(JSONData); } } }; And.. private Handler buttonImageHandler = new Handler() { public void handleMessage(Message msg){ //BT_debugger.showIt(activityName + ":buttonImageHandler setting background image for button."); //msg.what will equal the index of the button images array... //set the drawable... Drawable d; //we may need to round the image... if(buttonCornerRadius > 0){ d = buttonImages.get(msg.what); //we have a drawable, our rounding method needs a bitmap... Bitmap b = ((BitmapDrawable)d).getBitmap(); b = BT_viewUtilities.getRoundedImage(b, buttonCornerRadius); //convert it back to a drawable... d = new BitmapDrawable(b); }else{ d = buttonImages.get(msg.what); } buttonSquares.get(msg.what).setBackgroundDrawable(d); buttonSquares.get(msg.what).invalidate(); } }; I have been reading on stack overflow about making the handler static or weak but don't know how. Any ideas
 
Sandeep
Android Fan
Profile
Posts: 1260
Reg: Feb 01, 2012
Miraj, India
25,250
like
07/02/13 08:17 AM (11 years ago)
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
07/02/13 08:59 AM (11 years ago)
Hi @Sandeep, I've been following this and checked out the source code of Eric's app. There's some sort of memory leak going on that reducing image sizes doesn't fix. Even tiny images fill up the vm heap after around 4 button clicks. Before crashing, the last line of good executed code is always the "downloadScreenDataHandler" method. HPROF reports show images filling the vm heap rapidly, even when they're tiny. Weird.. Eric may be onto something with his OP.
 
Eric F
Lost but trying
Profile
Posts: 13
Reg: Mar 21, 2013
Clovis
3,380
like
07/02/13 09:20 AM (11 years ago)
@raveyd, what I have been reading is making a static handler but I have no idea to do that. It would be placed in the screendatahandler as well. Any thoughts?
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
07/02/13 10:52 AM (11 years ago)
I'm lost Eric. I've just seen your post on stackoverflow and two of the Android guru's are already in contradiction. At the end of the day it's David's code, I'd try contacting him about the issue as he'd be the best guy to ask, because at this point it's mostly guesswork from us (well, it is from me) and could take forever to find a fix. My thoughts are, the sooner it's in the market the better, it's a useful app, so go to the code creator.
 
Sandeep
Android Fan
Profile
Posts: 1260
Reg: Feb 01, 2012
Miraj, India
25,250
like
07/02/13 07:05 PM (11 years ago)
@raveyd- I was not knowing this one had some serious problem. Hope David jumps in with some solution. Or we can wait for the new release of BT Android version any day now and hope it has that solution.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.