I know that this was probably addressed, however, I have problems with memory leak in the Android app. I have a loop through a different picture in the users library every time they click a button. This works fine for the first pair and then throws an exception in memory. I looked around, and although I realized that the photos are stored in a heap (?) Even after they do not point to it. Is there a way to make this clear so that I don't get an error? I tried the following ....
private void setImage() throws RemoteException{ view.setBackgroundDrawable(null); currentBackground = Drawable.createFromPath(backgroundImageService.getCurrentImageLocation()); view.setBackgroundDrawable(currentBackground); }
UPDATE :: Update This worked !!!
private void setImage() throws RemoteException{ if(currentBackground != null){ currentBackground.recycle(); } currentBackground = BitmapFactory.decodeFile(backgroundImageService.getCurrentImageLocation()); view.setBackgroundDrawable(new BitmapDrawable(currentBackground)); }
thanks
source share