으로 사라지면 http://www.nhara.org/scored_races-2013.htm에서 정보를 수집하는 NSMutableData 변수가 있습니다. 약 90810 바이트가 포함되어있을 때 웹 사이트에서 정보를 얻은 후 약 세 번째 시간이 지나면 NSString을 인쇄하면 null이기 때문에 사라지거나 null이됩니다. 여기 내 NSMutableData 데이터를 저장한다는 것입니다 가장 나를 혼란 어떤 코드내 프로그램에서 NSMutableData가
- (void)viewWillAppear:(BOOL)animated
{
// Create a new data container for the stuff that comes back from the service
xmlData = [[NSMutableData alloc] initWithCapacity:180000];
[self fetchEntries];
[super viewWillAppear:animated];
}
- (void)fetchEntries
{
// Construct a URL that will ask the service for what you want
NSURL *url = [NSURL URLWithString: @"http://www.nhara.org/scored_races-2013.htm"];//
// Put that URL into an NSURLRequest
NSURLRequest *req = [NSURLRequest requestWithURL:url];
// Create a connection that will exchange this request for data from the URL
connection = [[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES];
}
- (void)connection:(NSURLConnection *)conn didReceiveData:(NSData *)data
{
// Add the incoming chunk of data to the container we are keeping
// The data always comes in the correct order
[xmlData appendData:data];
NSLog(@"%@",xmlData);
NSString *xmlCheck = [[[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding]autorelease];
NSLog(@"xmlCheck = %@", xmlCheck);
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"error= %@",error);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)conn {
// We are just checking to make sure we are getting the XML
NSString *xmlCheck = [[[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"xmlCheck2 = %@", xmlCheck);
}
이지만, 바이트 수를 동일하게 할 것을 주장하면서 다음을 잃는다.
NSMutableData의 크기에 제약이 있습니까? 아니면 단지 메모리 관리에 문제가 있습니까?
ARC를 사용하고있는 것으로 추측합니다. 변수가 dealloc되었습니다. 강력한 속성을 가진 @property로 선언하십시오. – Rog
@Rog 그는 ARC를 사용하지 않습니다.'autorelease'에 대한 호출을보세요? – rmaddy
어디서 문제가 보이나요? 'didReceiveData' 메소드 또는'didFinishLoading' 메소드에서? 부분 데이터 ('didReceiveData')를 변환하면 부분 데이터가 유효한 UTF8 문자열이 아니기 때문에'nil' 문자열이 생길 수 있습니다. – rmaddy