title: iOS Bluetooth retrievePeripherals causes EXC_BAD_ACCESS crash
body: <p>I need to periodically reconnect to a peripheral, but trying to re-connect crashes.</p>
  
  <p>First, my central scans for peripherals' UUID, then it connects, then it stores the peripheral.UUID into a CFUUIDRef variable, and then disconnects.  Next, to re-connect it retrieves the UUID from variable, then either crashes with "EXC_BAD_ACCESS" when it does retreivePeripherals, or a little later when it does the subsequent didRetrievePeripherals.</p>
  
  <p>Maybe I'm not storing the UUID correctly, but I don't see the bug.   Thanks.</p>
  
  <p>Here's the code ..........</p>
  
  <pre><code>-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
  {
      ///////////////////////   C E N T R A L   C O N N E C T E D   P E R I P H E R A L   //////////////////////
  
      [self.centralManager   stopScan];
      // Make sure we get the discovery callbacks
      peripheral.delegate = pwr_tx_management;
  
      switch( PWR_TX_manager.present_operation )
      {
          case POLLING_FOR_GENERIC_DVINEWAVE_DEVICE:
              if( dbg_ev )        printf("1");        
              // Add new record for connection device to local system status database:
              update_device_record( &amp;packed_ad_record    );       //      ==&gt;  device_record_index
              // Store peripheral UUID for later, perioed re-connection for polling:
              area_device_status[ device_area ][ device_record_index ].peripheral_UUID = peripheral.UUID;
                                   // uses declaration:  CFUUIDRef            peripheral_UUID;
  
      // Disconnect:        !!!
          [self.centralManager   cancelPeripheralConnection:   peripheral];
          break;
  
  
          case OPERATION_SPECIFIC_POLLING:
                                          NSLog( @"(7) didConnectPeripheral   " );
              if( dbg_ev )        printf("2");        
              // Proceed with reading device's status and updating local database:
                  [peripheral   discoverServices:nil];    // request service, characteristics, then request device send its packed status record
  
              break;
          default:
              break;
      }    
  }
  
  
  
  
  
  // Connects to device specificed by index next_dbase_record .
  void connect_specific_device( void )
  {
                                                          NSLog( @"(5) connect_specific_device    - next_dbase_record = %d", next_dbase_record );
      CFUUIDRef uuid = area_device_status[ device_area ][ next_dbase_record ].peripheral_UUID;
  
      if( uuid )
      {
          // Request call to didRetrievePeripherals() with CBPeripheral:
          [pwr_tx_management.centralManager retrievePeripherals:[NSArray arrayWithObject: (id)CFBridgingRelease(uuid)]];     &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; crashes here with:  Thread 1: EXC_BAD_ACCESS
      }
      else
      {
          NSLog( @"   - missing area_device_status[][].peripheral_UUID ");
      }
  
  }
  
  
  
  // Iniates connection to peripheral device specified before by retrievePeripherals.
  - (void) centralManager:(CBCentralManager *)central didRetrievePeripherals:(CBPeripheral *)peripheral
  {
      NSLog( @"(6) didRetrievePeripherals");
      [central   connectPeripheral:peripheral   options:nil];
  }
  </code></pre>