title: cfstring length message sent to deallocated instance?
body: <p>I m doing the concept of autocomplete feature for a textField and in doing so I m getting the following error:
  "cfstring length message sent to deallocated instance"</p>
  
  <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
     if( textField == txtcity)
      {
  
       autocompleteTableView.hidden = NO;
  
       NSString *substring = [NSString stringWithString:textField.text];
      substring = [substring stringByReplacingCharactersInRange:range withString:string];
      [self searchAutocompleteEntriesWithSubstring:substring];
      return YES;
      }
  }
  
  - (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {
  
      subString2=[NSString stringWithFormat:@"%@",substring];
  
  
      NSMutableData *data = [[NSMutableData alloc] init];
      self.receivedData = data;
      [data release];
  
      NSURL *jsonUrl =[NSURL URLWithString:[NSString stringWithFormat:@"http://210.90.32.122/services/AutoService.svc/GetCities/?p=%@&amp;k=%@",substring,txtId.text]];
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:jsonUrl];
  
      NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
                                                                    delegate:self];
       self.connection = connection;
      [connection start];
  }
  
  - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
  
  {
      [receivedData setLength:0];
  
  }
  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  
  {
      [receivedData appendData:data];
  
  }
  
  
  
  - (void)connectionDidFinishLoading:(NSURLConnection *)connection
  {
      parser = [[NSXMLParser alloc] initWithData:receivedData];
      [parser setDelegate:self];
      [parser setShouldProcessNamespaces:NO];
      [parser setShouldReportNamespacePrefixes:NO];
      [parser setShouldResolveExternalEntities:NO];
      [parser parse];
      [parser release];
      NSLog(@"%@",arr2);
      if([arr2 count]!=0)
      {
  
          self.autocompleteUrls = [[NSMutableArray alloc] init];
          if(autocompleteTableView)
              [autocompleteTableView removeFromSuperview];
          autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(88, 428, 200,[arr2 count]*20) style:UITableViewStyleGrouped];
          autocompleteTableView.delegate = self;
          autocompleteTableView.dataSource = self;
          autocompleteTableView.scrollEnabled = YES;
          autocompleteTableView.rowHeight=20;
  
          [self.view addSubview:autocompleteTableView];
                 for(int i=0;i&lt;[arr2 count];i++)
          {
              NSString *curString = [[arr2 objectAtIndex:i] valueForKey:@"Name"];
  
              NSRange substringRange = [curString rangeOfString:subString2];  //error at this line 
  
              if (substringRange.location == 0)
                  [autocompleteUrls addObject:curString];
  
          }
      }
  
  
      [autocompleteTableView reloadData];
      txtcity.text=subString2;
      [txtcity resignFirstResponder];
  
  }
  </code></pre>
  
  <p>my subString2 is becoming null.But I have retained it while decalring </p>
  
  <p>@property(nonatomic,retain)NSString *subString2;</p>
  
  <p>Where Im going wrong.Couldn't understand where it is being deallocated..</p>