0

My application is basically a image viewer. It is opened from both camera and as a separate application.

I open the image viewer to view and edit the picture. Each edit operation is implemented using thread. If my application closes due to pressing the home button, the next time I open it with camera. It throws anr.

This doesn't always happen. Only when large edit operations or edit operations on large image files are done.

I get out of memory error, sometimes timeout.

I guess it s because the thread doesn't complete the edit operation when home is clicked. and it s still running on the background. so when i open it s unable to process it.

m I right?

If so what is the way to stop a thread before the completion/

Can u pls help me out?

Indhu
  • 9,806
  • 3
  • 18
  • 17

3 Answers3

0

Looks like memory leak. Check for memory leaks in your code

Vinay
  • 4,743
  • 7
  • 33
  • 43
0

Might look at a thread I opened on out of memory issue on large images. Several suggestions in there on what might help you: Strange out of memory issue while loading an image to a Bitmap object

Community
  • 1
  • 1
Chrispix
  • 17,941
  • 20
  • 62
  • 70
  • I tried out recycle() and then gc... it worked out. It solved the out of memory issue... Thank you... :):) – Indhu Nov 19 '10 at 10:14
0

Threads are not garbage collected until they are stopped or their process is killed (which usually takes a while, even after all activities are closed). That also means that any objects referenced by those threads aren't garbage collected either.

There are multiple ways to shut down a thread, depending on what exactly it is doing. Best way is to check for a variable at certain points during it's execution, and exit the run-Method when that variable is set. Best place for that is usually within the condition of a while-loop. You can than set that variable from the outside, and the thread will shut down the next time it checks for it. Remember to mark that variable as volatile. Example:

private volatile boolean mStopped = false;

public void run() {
   while(!mStopped) {
      // do something
      if(mStopped)
          return;
      // do something more
   }
}

If a thread is waiting, you'll have to interrupt it. See the interrupt-Method of the Thread-Class for that.

Timo Ohr
  • 7,947
  • 2
  • 30
  • 20