title: "EXC_BAD_ACCESS: Unable to restore previously selected frame" Error, Array size?
body: <p>I have an algorithm for creating the sieve of Eratosthenes and pulling primes from it. It lets you enter a max value for the sieve and the algorithm gives you the primes below that value and stores these in a c-style array.</p>
  
  <p>Problem:
  Everything works fine with values up to 500.000, however when I enter a large value -while running- it gives me the following error message in xcode:</p>
  
  <pre><code>Program received signal:  “EXC_BAD_ACCESS”.
  warning: Unable to restore previously selected frame.
  Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not safe to call dlopen at this time.)
  </code></pre>
  
  <p>My first idea was that I didn't use large enough variables, but as I am using 'unsigned long long int', this should not be the problem. Also the debugger points me to a point in my code where a point in the array get assigned a value. 
  Therefore I wonder is there a maximum limit to an array? If yes: should I use NSArray instead? If no, then what is causing this error based on this information?</p>
  
  <p>EDIT:
  This is what the code looks like (it's not complete, for it fails at the last line posted). I'm using garbage collection.</p>
  
  <pre><code>/*--------------------------SET UP--------------------------*/
      unsigned long long int upperLimit = 550000;             // 
      unsigned long long int sieve[upperLimit];
      unsigned long long int primes[upperLimit];
      unsigned long long int indexCEX;
      unsigned long long int primesCounter = 0;
  
  // Fill sieve with 2 to upperLimit
  for(unsigned long long int indexA = 0; indexA &lt; upperLimit-1; ++indexA) {
          sieve[indexA] = indexA+2;
  }
  
  
  unsigned long long int prime = 2;
  
  /*-------------------------CHECK &amp; FIND----------------------------*/
  while(!((prime*prime) &gt; upperLimit)) {
  
      //check off all multiples of prime
      for(unsigned long long int indexB = prime-2; indexB &lt; upperLimit-1; ++indexB) {
  
          // Multiple of prime = 0
          if(sieve[indexB] != 0) {
              if(sieve[indexB] % prime == 0) {
                  sieve[indexB] = 0;
              }
          }
      }
  
      /*---------------- Search for next prime ---------------*/
      // index of current prime + 1
      unsigned long long int indexC = prime - 1;
  
      while(sieve[indexC] == 0) {
          ++indexC;
      }
      prime = sieve[indexC];
  
      // Store prime in primes[]
      primes[primesCounter] = prime; // This is where the code fails if upperLimit &gt; 500000
      ++primesCounter;
  
      indexCEX = indexC + 1;
  
  }
  </code></pre>
  
  <p>As you may or may not see, is that I am -very much- a beginner. Any other suggestions are welcome of course :)</p>