1

I am using a hough transform to find circles in an image on android. At once point I get a stack overflow:

12-03 16:18:20.999: I/dalvikvm-heap(21563): Grow heap (frag case) to 29.662MB for 2253716-byte allocation
12-03 16:18:21.014: I/dalvikvm(21563): threadid=11: stack overflow on call to Lorg/DTS/boltSizer/ImageProcessing/hystThresh;.hystConnect:VII
12-03 16:18:21.014: I/dalvikvm(21563):   method requires 44+20+12=76 bytes, fp is 0x5e949338 (56 left)
12-03 16:18:21.014: I/dalvikvm(21563):   expanding stack end (0x5e949300 to 0x5e949000)

Here is where the error is being thrown:

    private void hystConnect(int x, int y) {

        int value = 0;
        for (int x1=x-1;x1<=x+1;x1++) {
            for (int y1=y-1;y1<=y+1;y1++) {
                if ((x1 < width) & (y1 < height) & (x1 >= 0) & (y1 >= 0) & (x1 != x) & (y1 != y)) {
                    value = (input[y1*width+x1])  & 0xff;
                    if (value != 255) {
                        if (value >= lower) {
                            input[y1*width+x1] = 0xffffffff;
                            hystConnect(x1, y1);
                            ran++;

                        } 
                        else {
                            input[y1*width+x1] = 0xff000000;
                        }
                    }
                }
            }
        }

    }   

I think I understand what it means, but how does one go avoiding this. If you need more of the code being ran just ask.

Aaron Decker
  • 559
  • 9
  • 25

1 Answers1

0

Start with this:

How to increase the Java stack size?

Android: Increase call stack size

Ultimately this just means your function is consuming a lot of memory and you will have to find a more efficient algorithm. This is similar to if you posted an O(e^n) function and asked how to make it go faster. If this is your situation then you will want to research a more space-efficient algorithm to use.

Community
  • 1
  • 1
djechlin
  • 59,258
  • 35
  • 162
  • 290