Recursive selection sort stack overflow

hi, first time posting here.
i have to write a java method that implements a selection sort. This method must be recursive. ok not a problem. i have come up with this so far
    public int findMin(int index) {
        int min = index - 1;
        if (index < num.length - 1) min = findMin(index + 1);
        if (num[index] < num[min]) min = index;
        return min;
    public void selectionSort(int left) {
        if (left < num.length - 1) {
            swap(left, findMin(left));
            selectionSort(left + 1);
    public void swap(int index1, int index2) {
        int temp = num[index1];
        num[index1] = num[index2];
        num[index2] = temp;
    }which works fine until i toss in a lot of values into the array. this creates a stack overflow, and ive been told that i need to use the divide and conquer method of resolving this issue. I guess this means to split the array up and sort each half seperatly, again and agin, or so im told.
My question is how do i go about doing this, i am at a loss. Any help at all would be great.
thank you
lance

i get this when i push the array passed about 5500 in sizeI got no problem. Post a small demo code that is generally compilable, runnable and could reproduce your problem. See: http://homepage1.nifty.com/algafield/sscce.html and http://www.yoda.arachsys.com/java/newsgroups.html
It is silly to implement selection sort with recursion, double-silly if you use double-recursion as your current code.
/* silly but no OOME when used against 5500 element array */
import java.util.*;
public class RecursiveSelectionSort{
  static int[] num;
  public static int findMin(int index) {
    int min = index; // your code had a bug here
    if (index < num.length - 1){
      min = findMin(index + 1);
    if (num[index] < num[min]){
      min = index;
    return min;
  public static void selectionSort(int left) {
    if (left < num.length - 1) {
      swap(left, findMin(left));
      selectionSort(left + 1);
  public static void swap(int index1, int index2) {
    int temp = num[index1];
    num[index1] = num[index2];
    num[index2] = temp;
  public static void main(String[] args){
    Random rand = new Random();
    int n = 10;
    if (args.length > 0){
      n = Integer.parseInt(args[0]);
    num = new int[n];
    for (int i = 0; i < num.length; ++i){
      num[i] = rand.nextInt(10000);
    selectionSort(0);
    for (int in : num){
      System.out.print(in + " ");
    System.out.println();
}

Similar Messages

  • Unrecoverable Stack Overflow

    Hi there,
    I have a thread that does various things including hibernate transactions. After everything is done it calls the run method again so its a endless loop. Inside the run function there are a couple of loops. After running this thread for a day I get this error, what does it mean?
    Unrecoverable Stack Overflow: addr=403d3a26, ee=8401b80, er=430fdb00
    JVMDG217: Dump Handler is Processing a Signal - Please Wait.
    JVMDG303: JVM Requesting Java core file
    kill: usage: kill [-s sigspec | -n signum | -sigspec] [pid | job]... or kill -l [sigspec]
    kill: usage: kill [-s sigspec | -n signum | -sigspec] [pid | job]... or kill -l [sigspec]

    I have a thread that does various things including
    hibernate transactions. After everything is done it
    calls the run method again so its a endless loop.Are you seriously saying that the run() method calls itself, like in public run() {
        run();
    }This would not be an endless loop, but an infinite recursion and the stack overflow is not at all surprising. If this is your only bug then rewrite topublic run() {
      while( true ) {
    }and everything will be just fine.
    Harald.

  • Stack overflow exception when selecting the Organization tab on a contact card

    I have encountered a reproducible crash in the Lync 2013 client.  The crash happens after selecting the "Organization" tab when viewing a contact card.
    The crash appears to happen because of a stack overflow with MSO.DLL.  I have applied the latest hotfix for that module but the crash persists.
    Before I open a case with MSFT, can anyone offer any insight?  Perhaps this is being seen elsewhere?
    Exception Stack:
    SYMBOL_NAME:  mso!Ordinal3863+4970
    FOLLOWUP_NAME:  MachineOwner
    MODULE_NAME: MSO
    IMAGE_NAME:  MSO.DLL
    DEBUG_FLR_IMAGE_TIMESTAMP:  50ee6c2f
    FAILURE_BUCKET_ID:  STACK_OVERFLOW_c00000fd_MSO.DLL!Ordinal3863
    BUCKET_ID:  APPLICATION_FAULT_STACK_OVERFLOW_mso!Ordinal3863+4970
    WATSON_STAGEONE_URL: 
    http://watson.microsoft.com/StageOne/lync_exe/15_0_4420_1017/5067326f/bcryptprimitives_dll/6_1_7600_16385/4a5bd987/c00000fd/000048c0.htm?Retriage=1
    Followup: MachineOwner
    0:004> kvn 1000
     # ChildEBP RetAddr  Args to Child             
    00 042c314c 738d4863 128db2d0 00000000 00000000 bcryptprimitives!AesCtrRng_Generate+0x1e (FPO: [Non-Fpo])
    01 042c321c 738d47a4 128db2b8 1524cb1b 00000008 bcryptprimitives!MSCryptAesCtrGen+0x166 (FPO: [Non-Fpo])
    02 042c3248 72781e65 0c2c8ae8 1524cb1b 00000008 bcryptprimitives!MSCryptGenRandom+0xc9 (FPO: [Non-Fpo])
    03 042c3260 6b8c1de1 12811348 1524cb1b 00000008 bcrypt!BCryptGenRandom+0x5c (FPO: [Non-Fpo])
    04 042c3278 65daaa26 1524cb1b 00000008 042c32ac cryptdll!DefaultRngFn+0x21 (FPO: [Non-Fpo])
    05 042c3288 65db4a73 1524cb1b 00000008 00000000 kerberos!KerbRandomFill+0x10 (FPO: [Non-Fpo])
    06 042c32ac 65daa2ec 1524cb05 80000001 042c3484 kerberos!KerbMakeSignatureToken+0x4e8 (FPO: [Non-Fpo])
    07 042c341c 750df30c 128d8248 80000001 042c34a8 kerberos!SpSealMessage+0x3d7 (FPO: [Non-Fpo])
    08 042c343c 750e128c 070c6c80 80000001 042c34a8 sspicli!LsaSealMessage+0x6e (FPO: [Non-Fpo])
    09 042c3460 7707ad44 0c53adfc 80000001 042c34a8 sspicli!EncryptMessage+0x3e (FPO: [Non-Fpo])
    0a 042c34d0 7707abdc 1513b5f0 00000132 00000000 Wldap32!CryptStream::SignAndSealLdapStream+0x184 (FPO: [Non-Fpo])
    0b 042c3518 770745d6 1513b5f0 000000d7 00000006 Wldap32!CryptStream::LdapSendSsl+0x12b (FPO: [Non-Fpo])
    0c 042c3534 77078527 0c53af5c 1278cef8 00000000 Wldap32!LdapSend+0xd8 (FPO: [Non-Fpo])
    0d 042c3558 770787b2 12c79fa0 0c53ad78 12597998 Wldap32!SendLdapSearch+0x64a (FPO: [Non-Fpo])
    0e 042c3594 770a91f4 0c53ad78 152f06e4 00000000 Wldap32!LdapSearch+0x28f (FPO: [Non-Fpo])
    0f 042c35e0 585c882f 0c53afa4 152f06e4 00000000 Wldap32!ldap_search_extW+0x48 (FPO: [Non-Fpo])
    WARNING: Stack unwind information not available. Following frames may be wrong.
    10 042c3624 585d2b7c 00000000 402af114 152f06e4 MSO!Ordinal8903+0x4f04
    11 042c3734 585d30e0 152f06e4 042c3768 12ae9be0 MSO!Ordinal3863+0x43b6
    12 042c3aa8 585d3136 152f06e4 12ae9be0 0c385808 MSO!Ordinal3863+0x491a
    13 042c3e14 585d3136 152e4d94 12ae9be0 0c385808 MSO!Ordinal3863+0x4970
    14 042c4180 585d3136 152f0404 12ae9be0 0c385808 MSO!Ordinal3863+0x4970
    <SNIP>
    4b1 043bfb44 579e9c53 1293ddb0 043f7130 043bfb6c MSO!Ordinal2317+0x240
    4b2 043bfb54 579e9bf7 1293ddb8 12c54790 1293ddb8 MSO!Ordinal2317+0x12b
    4b3 043bfb6c 5778abcd 1293ddb8 12c54790 5777ccab MSO!Ordinal2317+0xcf
    4b4 043bfb9c 5777bc92 043bfc0c 043bfbf0 003602e0 MSO!Ordinal5372+0x66
    4b5 043bfbb4 57778a6f 043bfc0c 00000000 003602e0 MSO!Ordinal4578+0x1bc
    4b6 043bfbe8 577776fd 00000000 577776fd 043bfc0c MSO!Ordinal630+0x18ed
    4b7 043bfc3c 768033aa 003602e0 043bfc88 77a19ef2 MSO!Ordinal630+0x57b
    4b8 043bfc48 77a19ef2 003602e0 69d72777 00000000 kernel32!BaseThreadInitThunk+0xe (FPO: [Non-Fpo])
    4b9 043bfc88 77a19ec5 577776a4 003602e0 ffffffff ntdll!__RtlUserThreadStart+0x70 (FPO: [Non-Fpo])
    4ba 043bfca0 00000000 577776a4 003602e0 00000000 ntdll!_RtlUserThreadStart+0x1b (FPO: [Non-Fpo])
    0:004> lmivm mso
    start    end        module name
    57760000 58f92000   MSO        (export symbols)       MSO.DLL
        Symbol file: MSO.DLL
        Image path: C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\MSO.DLL
        Image name: MSO.DLL
        Timestamp:        Thu Jan 10 01:22:23 2013 (50EE6C2F)
        CheckSum:         01833BC0
        ImageSize:        01832000
        File version:     15.0.4481.1000
        Product version:  15.0.4481.0
        File flags:       0 (Mask 3F)
        File OS:          40004 NT Win32
        File type:        2.0 Dll
        File date:        00000000.00000000
        Translations:     0000.04e4
        CompanyName:      Microsoft Corporation
        ProductName:      Microsoft Office 2013
        InternalName:     MSO
        OriginalFilename: MSO.DLL
        ProductVersion:   15.0.4481.1000
        FileVersion:      15.0.4481.1000
        FileDescription:  Microsoft Office 2013 component

    I actually think I may have figured this out.  I took a network trace during the crash.  What I found is that Lync is performing repeated LDAP searches over and over until it crashes from the stack overflow.  Digging into
    the searches, I found the same two user CN's being alternated one after another.
    It appears that this crash may be the result of a "Circular Reference" where the two users are each listed as the others manager in their user object.
    Example:
    User1: Manager = User2
    User2: Manager = User1
    Proving this as the cause will take me some additional time as these two users are at the top of the Org Chart.  :)
    I'll update this post with the results when I get them. 

  • Recursive function definition results in stack overflow

    I am writing a library script to handle some basic calculations with complex numbers which includes a function, powerN(), that raises (or is supposed to raise) a complex number to the Nth power. The function compiles but gives a stack overflow error when called. The language guide has an example (p. 286 in PDF version- recursive subroutines section) of a recursive definition of a function which gives the factorial of a number, and my powerN function seems to be analogous. Can anyone shed some light on whatever the problem is? Relevant code examples are below. Thanks for any insights.
    -----Apple recursive subroutine for factorials------
    on factorial(x)
    if x > 0 then
    return x * (factorial(x - 1))
    else
    return 1
    end if
    end factorial
    -----End Apple recursive subroutine for factorials------
    -----My script with problematic powerN() function------
    --Complex numbers a+b(i), x+y(i) represented by {a,b}, {x,y}
    on multiply({a, b}, {x, y})
    return {(a * x + b * y), (b * x + a * y)}
    end multiply
    --above multiply function works
    on powerN({a, b}, N)
    return multiply({a, b}, powerN({a, b}, N - 1))
    end powerN
    --above powerN function gives stack overflow error
    -----End my script with problematic powerN() function------

    the problem is that your recursion has no end case, thus causing a stack overflow
    you should add a test as follows :
    on powerN({a, b}, N)
    if N>0 then
    return multiply({a, b}, powerN({a, b}, N - 1))
    else
    return 1
    end if
    end powerN
    by the way, shouldn't your complex multiplication look like :
    on multiply({a, b}, {x, y})
    return {(a * x - b * y), (b * x + a * y)}
    end multiply

  • Stack overflow error while creating connection using Oracle10G dirver

    Hi,
    Our web application built on Servlets runs on the iPlanet web server (In solaris machine). Earlier we used JDK 1.5 update 6 with oracle 9i driver and now got migrated to JDK 1.5 update 10 with same driver. Everything went fine until we started testing the environment with oracle 10G driver. Java 1.5 update 10 with oracle 10G driver throws "Stack overflow error".
    Driver version is - 10.2.0.2.0
    This occurs only when I access the portal. When I created the single main program and try to run it in the solaris machine it works fine. But wen I try to access the portal keeping this driver under classpath, it fails. Please let me know if anyone have any clues.
    When I looked into it, I am able to find that the "stack overflow error" occurs at the point the code line DriverManager.Getconnection("url", "username", "pwd") executes.
    Thanks in advance
    below the stacktrace of the exception from webserver error log..
    06/Mar/2007:04:20:40] failure (10198):
    for host 202.54.182.136 trying to POST /wr/servlet/WorkRequest, service-j2ee reports: StandardWrapperValve[WorkRequest]: WEB2769: Allocate exception for servlet WorkRequest
    javax.servlet.ServletException: WEB2778: Servlet.init() for servlet WorkRequest threw exception
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:949)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:658)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:244)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:209)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:161)
    at com.iplanet.ias.web.WebContainer.service(WebContainer.java:580)
    ----- Root Cause -----
    java.lang.StackOverflowError
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(
    [06/Mar/2007:04:22:20] info (10198):
    CORE5073: Web server shutdown in progress
    [06/Mar/2007:04:22:21] info (14506):
    CORE1116: Sun ONE Web Server 6.1SP5 (64-Bit) B12/02/2005 04:37
    [06/Mar/2007:04:22:21] warning (14513):
    CORE1251: On group ls1, servername pstst42.pedc.sbc.com does not match subject "" of certificate Server-Cert.
    [06/Mar/2007:04:22:21] warning (14513):
    CORE1250: In secure virtual server https-vts, urlhost does not match subject "" of certificate Server-Cert.
    [06/Mar/2007:04:22:21] info (14513):
    CORE5076: Using [Java HotSpot(TM) 64-Bit Server VM, Version 1.5.0_06] from [Sun Microsystems Inc.]
    [06/Mar/2007:04:22:21] info (14513):
    WEB0100: Loading web module in virtual server [https-vts] at [servlet]
    [06/Mar/2007:04:22:21] info (14513):
    WEB0100: Loading web module in virtual server [https-vts] at [vts/servlet]
    [06/Mar/2007:04:22:21] info (14513):
    WEB0100: Loading web module in virtual server [https-vts] at [cron/servlet]
    [06/Mar/2007:04:22:21] info (14513):
    WEB0100: Loading web module in virtual server [https-vts] at [find/servlet]
    [06/Mar/2007:04:22:21] info (14513):
    WEB0100: Loading web module in virtual server [https-vts] at [cb/servlet]
    [06/Mar/2007:04:22:21] info (14513):
    WEB0100: Loading web module in virtual server [https-vts] at [wr/servlet]
    [06/Mar/2007:04:22:21] info (14513):
    WEB0100: Loading web module in virtual server [https-vts] at [search]
    [06/Mar/2007:04:22:25] info (14513):
    HTTP3072: [LS ls1] ready to accept requests
    [06/Mar/2007:04:22:25] info (14513):
    CORE3274: successful server startup
    Message was edited by:
    Nandakumar_s
    Message was edited by:
    Nandakumar_s

    Yes, request goes through connection pool but weird
    thing is application throws stack excatly where
    DriverManager.getConnection gets executed.
    Not weird at all.
    This is what I am guessing that you did. You changed the driver and some other stuff, like configuration information.
    Then when it blew up you tracked down in your code where you see the stack overflow. That happens to be on the connection line. That is not where the overflow 'occurs' - it merely represents where you saw it.
    That line however isn't using the oracle driver. What it is using is a connection pool of some sort. That connection pool is configured somewhere. And that configuration is self-referential (or maybe refers to a another driver which refers back to the original.)
    And that causes you stack over flow.

  • Stack overflow user profile doesn't display correctly

    The page of Stack overflow user profile is wrongly displayed, blank space on top of page and some info is hidden.

    I see what you mean. It appears that the drop-down which says "Summary" is pushing that block of content off to the right (sometimes you can see a sliver of it at the right edge of the page). That problem doesn't occur in the stock Android (2.3.4) browser.
    If I use a Fennec useragent string in the User Agent Switcher extension, I can replicate the problem on a desktop browser (''Firefox 13 beta 4''). The drop-down is floated within a container that uses 100% of the width of the screen. The next element floats up alongside the &lt;select> rather than dropping down beneath it because that next element doesn't have a specified width or minimum width.
    StackOverflow can solve this problem by editing its CSS to include a clearing rule:
    <br>.inner-wrap {
    padding: 5px;
    overflow: auto;
    '''clear: left;'''
    However, as end users, I don't know whether there is anything we can do.
    This problem has appeared in sites for years, and it seems unlikely that Firefox will change the way it handles floats to work around developers who forget to clear them. (Guessing as to what the developer must have wanted was something that IE did for years, but I think even Microsoft is starting to require developers to pay closer attention.)

  • Stack overflow error

    Hi..
    I have problem with this code.
       class test
           test tt=new test();   //1
           String name1;
        test() {}
        test(String i)
              name1=i;
             //tt=new test();    //2
       public static  void main(String arg[]){
                  test t1=new test("kj"); //3
    }  When I use line 2 (nstead of line 1 ) for initializing the ref variable iam not having any problem.
    But if i use as in line 1 iam getting stack overflow error..
    I thought tht calling a constructor recursivley results in a stack overflow error..
    But iam instantiating t1 with a one arg constructor (line 3) for which tt (line 1)is intialized,then where is the recursion happening..
    can any one pls clear..
    Thnx.
    mysha..

    please use [code][/code] tags around your code - makes it much easier to read.
    I think you have it - consider this code:public class StackOverflower {
        private StackOverflower so = new StackOverflower();
        public static void main(String[] args) {
            StackOverflower mySO = new StackOverflower();
    }Running this will overflow the stack since creation of an instance of StackOverflower requires creation of an instance of StackOverflower. This code though:public class NonStackOverflower {
        private NonStackOverflower nso = null;
        public NonStackOverflower() {
        public NonStackOverflower(String s) {
            this.nso = new NonStackOverflower();
        public static void main(String[] args) {
            NonStackOverflower myNSO = new NonStackOverflower();
    }Won't, since the creation of a new NonStackOverflower is not required to create a new NonStackOverflower instance.
    Did that make sense? I may have gotten confused and failed to illustrate your situation with my code...
    Good Luck
    Lee

  • Stack OverFlow Problem with QuickSort Partition, please help.

    I have a Quicksort method that keeps running into a Stack OverFlow error when it attempts to partition.
    Here are my methods:
    public static void quickSort(int[] a){
              int from = 0;
              int to = a.length - 1;
              sort(a, from, to);
    private static int partition(int[] a, int from, int to){  
              int pivot = a[from];  
              int i = from - 1; 
              int j = to + 1;  
              while (i < j){
                   i++; while (a[i] < pivot) i++;     
                   j--; while (a[j] > pivot) j--;     
                   if (i < j) swap(a, i, j);    
              return j;
         private static void sort(int[] a, int from, int to){  
              if (from >= to) return;  
              int p = partition(a, from, to); // eclipse tells me my error is here.
              sort(a, from, p);  
              sort(a, p + 1, to); // I also have an error here.
         }Eclipse points to the sort method as the source of my error, which itself points to my attempting to partition the sucker, so I don't know what's up. It's probably something stupid, but I'm lost, so any help is appreciated.

         private static void swap(int[] a, int i, int j){
                   int temp = a;
              a[i] = a[j];
              a[j] = temp;
              }The quicksort method works until the array size is greater than 9723. That's when I get my overflow error.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How do I fix a stack overflow?

    Hi,
    Well I hope I am posting this in the right section of topics.
    I am new to programing.At the moment I am sudying loops in Java.
    I did something that has caused
    a "stack overflow" in my computer(Whatever that is).
    Is this really bad for my computer, and how do I fix it?
    thanks.

    Just to add a little more..
    The Stack is a special area of memory in the virtual machine. It stores variables that fall in and out of scope. When methods are called, the values of variables are often placed on the stack. The problem with a stack overflow arises when a method calls itself, either directly or indirectly, and never stops doing so. This could be called 'uncontrolled recursion'.
    When this happens, the stack will fill up until the method can no longer be called, and at this point a StackOverflowError will be thrown.
    It is important to note that this will not do bad things to your machine, because the stack is quite small (circa 256KB ?). If you don't catch the Error with a catch(Throwable) statement, the VM will exit automatically - all you have to do is fix the bug.

  • Getting stack overflow exception whilst reading from HashMap

    hi,
    We are getting stack oveflow exception exception whilst reading from the HashMap.
    Following are few details about the code
    We have a swing based client and Session beans and Entity beans deployed on Weblogic Server.
    When the server is started, a session bean method queries to data base and creates a java object for each row in the data base.This java object is then stored in HashMap. These java objects have all get/set methods . and it has attributes of primitive data type as well as other java objects.This Hahsmap is then returned to client.
    When client calls this method and the method processes succesfuly , but when tries to return the HashMap, it gives Stack overflow exception.
    Looking at the stack trace i think this exception is thrown when the HashMap.readObject() methods is being invoked.
    does any body have any idea about this ? a quick help is much appriciated.

    Stack overflow is often caused by infinity loops No, an infinite loop would be like while (true) {
        // stuff
    } That doesn't cause stack overflow.
    or
    recursive method calls.Bingo.

  • Stack overflow resolution and question

    on Oct 8th, I posted the stack overflow at the end of this message. I
    figured out the problem, but would like some insight into why it manifested
    itself as a stack overflow. Why isn't it a heap overflow? I care which
    overflows because a problem could still exist.
    PROBLEM
    Our server transmits an event object to our client. The event object has
    references to 2 member objects which describe the context of the event.
    About 200 of each type of member object is created. They are kept in a
    HashMap so we can reuse them.
    However, in one case, a new member object is created every time an event is
    transmitted. That's the bug - about a thousand events a second are created
    so one thousand of each member object is created, then transmitted. When we
    changed the member object creation to a member HashMap lookup, the stack
    trace stopped.
    PROFILING
    To isolate the problem, we profiled the client with OptimizeIt. This
    showed about 150,000 member objects and about 148,000
    java.io.ObjectInputStream$HandleTable$HandleList instances. In some runs,
    Garbage collection reduced the number to about 60,000. In other runs,
    Garbage Collection did not run before the stack error occurred.
    If we create lots of member objects in the heap, then the heap should
    overflow. Why does the stack overflow?
    ERROR MESSAGE
    The declaration is
    Socket sock = new Socket( hostname, port );
    ObjectInputStream is = new ObjectInputStream( sock.getInputStream() );
    ObjectOutputStream os = new ObjectOutputStream( sock.getOutputStream() );
    java.lang.StackOverflowError
    at COM.jrockit.io.NativeIOInputStream.read([BII)I(Optimized Method)
    at java.io.ObjectInputStream$PeekInputStream.read([BII)I(Optimized Metho
    d)
    at java.io.ObjectInputStream$BlockDataInputStream.read([BIIZ)I(Unknown S
    ource)
    at java.io.ObjectInputStream$BlockDataInputStream.readFully([BIIZ)V(Unkn
    own Source)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    Jeff
    Jeff
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Well, the HandleList entries mark a dependency from a parent object to a
    child (i.e referer and referee), and my guess is that you at some point
    simply manage to serialize a very long object chain:
    Obj1 -[ ref to]-> Obj2 -[ref to]-> Obj3 and so on.
    This will cause a recursive deserialization (actually, it causes a
    recursive serialization also, so sender should SOE as well). The amount
    of memeory used is probably high, but not OOM high. Note, that for this
    to happen, all objects sent must be unique, which you state that they
    are. Question is how you've managed to create an object chain like this.
    Another explanation might be that there is actually a bug somewhere in
    the sender that causes a circular reference between two (or more)
    objects to be sent not as reference handles, but unique objects. I
    cannot see what would cause this though. I assume that you don't have
    concurrency issues (i.e only one thread uses the ObjectOutput/Input
    streams at one time)?
    Do you have an exact count of the transmitted object? It might help me
    figure out exactly what happend.
    /C
    Jeff wrote:
    on Oct 8th, I posted the stack overflow at the end of this message. I
    figured out the problem, but would like some insight into why it manifested
    itself as a stack overflow. Why isn't it a heap overflow? I care which
    overflows because a problem could still exist.
    PROBLEM
    Our server transmits an event object to our client. The event object has
    references to 2 member objects which describe the context of the event.
    About 200 of each type of member object is created. They are kept in a
    HashMap so we can reuse them.
    However, in one case, a new member object is created every time an event is
    transmitted. That's the bug - about a thousand events a second are created
    so one thousand of each member object is created, then transmitted. When we
    changed the member object creation to a member HashMap lookup, the stack
    trace stopped.
    PROFILING
    To isolate the problem, we profiled the client with OptimizeIt. This
    showed about 150,000 member objects and about 148,000
    java.io.ObjectInputStream$HandleTable$HandleList instances. In some runs,
    Garbage collection reduced the number to about 60,000. In other runs,
    Garbage Collection did not run before the stack error occurred.
    If we create lots of member objects in the heap, then the heap should
    overflow. Why does the stack overflow?
    ERROR MESSAGE
    The declaration is
    Socket sock = new Socket( hostname, port );
    ObjectInputStream is = new ObjectInputStream( sock.getInputStream() );
    ObjectOutputStream os = new ObjectOutputStream( sock.getOutputStream() );
    java.lang.StackOverflowError
    at COM.jrockit.io.NativeIOInputStream.read([BII)I(Optimized Method)
    at java.io.ObjectInputStream$PeekInputStream.read([BII)I(Optimized Metho
    d)
    at java.io.ObjectInputStream$BlockDataInputStream.read([BIIZ)I(Unknown S
    ource)
    at java.io.ObjectInputStream$BlockDataInputStream.readFully([BIIZ)V(Unkn
    own Source)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)
    at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.O
    bjectStreamClass;)V(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Opt
    imized Method)
    at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.i
    o.ObjectStreamClass;)V(Optimized Method)

  • CIN stack overflow error

    Im using an recursiv c++ function in my VI.
    After severall calls the VI crashes, printing an
    stack overflow error.
    I already increased in Visual Studio 6.0 the Link
    setting: allocate stack. But nothing changed.
    I need help fix this problem!!
    My prg. looks like this:
    recursiv (....) {
    int array[..][..][..];
    recursiv (..);
    Sent via Deja.com http://www.deja.com/
    Share what you know. Learn what you don't.

    > Im using an recursiv c++ function in my VI.
    > After severall calls the VI crashes, printing an
    > stack overflow error.
    > I already increased in Visual Studio 6.0 the Link
    > setting: allocate stack. But nothing changed.
    > I need help fix this problem!!
    >
    > My prg. looks like this:
    >
    > recursiv (....) {
    > int array[..][..][..];
    > ....
    > recursiv (..);
    > }
    If you are truly allocating a three D array of ints
    on the stack, then it makes sense that you will run
    out of stack space sooner or later. I can't help
    you with increasing the stack size, but if you move
    your array into a memory block and store the pointer
    on the stack, then you will use less stack space and
    avoid the problem.
    In otherwords:
    recursive() {
    int *array;
    array= DSNewPtr()
    array[][][]= ...
    recursive();
    DSDisposePtr();
    Greg McKaskle

  • Simple CFM forms getting Stack Overflow

    What causes the error message "Stack Overflow at Line #" ?
    How can I fix it. I get this error message in very simple,
    uncomplicated .CFM forms upon submit.

    Stack Overflow
    Check the usual suspects: infinite loops or recursions, and
    rampant object creation.

  • Stack overflow (0xC00000FD) at EIP=0x01B13469

    Hello, 
    I am working on a large project and sometimes the LabView shuts down with the error message:  Stack overflow (0xC00000FD) at EIP=0x01B13469 (that is tha last one I got). I am not able to identify the generator of this error. ( Maybe someone can do it from the error message above).  It is possible to catch this error ???? 

    charlie87 wrote:
    Hello, 
    I am working on a large project and sometimes the LabView shuts down with the error message:  Stack overflow (0xC00000FD) at EIP=0x01B13469 (that is tha last one I got). I am not able to identify the generator of this error. ( Maybe someone can do it from the error message above).  It is possible to catch this error ???? 
    This is a fatal error. As to catching it, Windows does it already for you, that is why you see the dialog. Trying to catch it yourself by some means wouldn't add anything as it is ABSOLUTELY unsafe to continue the process after this error. It could eat your breakfast, or the harddisk or something else!!
    Something in your application is using huge stack space. This could be in LabVIEW itself, if you use some form of very strange VI settings, but since the LabVIEW VI execution itself is not stack based it is unlikely that the large project in itself would be the cause of it. Most likely you make use of some external code library somewhere, that has huge stack space requirements, either by allocating huge buffers on the stack (a very bad thing to do) or by calling functions recursively without a safe upper bound (just as a bad thing to do).
    Also you should qunatify what a large project means. I have done projects in LabVIEW with about 1000 VIs and more already 15 years ago.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Stack looses pick when selecting in stack mode

    Quite often when selecting the best item in a stack (alt-T view) the stack looses its stackpick. On the lefthand side of the screen (where the current pick should be displayed) only black emptiness is shown (this is the bug), the righthand side shows the currently selected item (which is how it should be).
    It is quite simple to get the stackpic back to display again, but it is very annoying.
    I have not been able to pinpoint it such that it can be reproduced with 100% certainty. I will describe the circumstance in which it happens in my case (don't know what is essential for this bug to raise its head). It happens in a 4500 images large library, in a 4300 images project. The database is repaired quite often (once to several times daily, because of thumbnails bug). I also quite often use the split-browser view (showing two projects/albums) in the browser (alt-clicking a project or album gives the split browser view). Sometimes the same images are shown in both projects/albums shown in the browser).
    Does anyone else also experience this problem?
    Koen

    I actually think I may have figured this out.  I took a network trace during the crash.  What I found is that Lync is performing repeated LDAP searches over and over until it crashes from the stack overflow.  Digging into
    the searches, I found the same two user CN's being alternated one after another.
    It appears that this crash may be the result of a "Circular Reference" where the two users are each listed as the others manager in their user object.
    Example:
    User1: Manager = User2
    User2: Manager = User1
    Proving this as the cause will take me some additional time as these two users are at the top of the Org Chart.  :)
    I'll update this post with the results when I get them. 

Maybe you are looking for