나는 다른 문제를 찾는 시도하지만, 그래서 여기에 맞게 아무것도 찾을 수 없습니다 간다 :할당이 해제 된 메모리 : 할당이 해제 된 인스턴스에 보낸 메시지가
나는 그래서이 사용하는 테이블보기에서 텍스트를 표시하기 위해 노력하고있어 코드의 비트 : [CFDictionary 자료] : 나는이 오류가 비록 chosenStock 개체를 해제하려고 할 때
// StockData is an object I created and it pulls information from Yahoo APIs based on
// a stock ticker stored in NSString *heading
NSArray* tickerValues = [heading componentsSeparatedByString:@" "];
StockData *chosenStock = [[StockData alloc] initWithContents:[tickerValues objectAtIndex:0]];
[chosenStock getData];
// Set up the cell...
NSDictionary *tempDict = [chosenStock values];
NSArray *tempArr = [tempDict allValues];
cell.textLabel.text = [tempArr objectAtIndex:indexPath.row];
return cell;
이 모든 cellForRowAtIndexPath
을 받고있다 할당이 해제 된 경우 0x434d3d0
을에 보낸 메시지Ive는 NSZombieEnabled 및 Build and Analyze를 사용하여 문제를 탐지했지만 지금까지는 문제가 없었습니다. 필자는 심지어 NSLog로 코드의 조각과 조각을 논평했지만 행운은 없었다. 이 아래 StockData 코드를 게시 할 것입니다. 내가 릴리스를하기 전에 무언가가 할당 해제되는 것으로 파악 될 수있는 한, 어떻게 확신 할 수는 없습니다. 내 코드에서 릴리스 된 유일한 곳은 dealloc 메서드 호출입니다.
다음은 StockData 코드입니다 :
이// StockData contains all stock information pulled in through Yahoo! to be displayed
@implementation StockData
@synthesize ticker, values;
- (id) initWithContents: (NSString *)newName {
if(self = [super init]){
ticker = newName;
}
return self;
}
- (void) getData {
NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"http://download.finance.yahoo.com/d/quotes.csv?s=%@&f=%@&e=.csv", ticker, @"chgvj1"]];
NSError *error;
NSURLResponse *response;
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSData *stockData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(stockData) {
NSString *tempStr = [[NSString alloc] initWithData:stockData encoding:NSASCIIStringEncoding];
NSArray *receivedValuesArr = [tempStr componentsSeparatedByString:@","];
[tempStr release];
values = [NSDictionary dictionaryWithObjects:receivedValuesArr forKeys:[@"change, high, low, volume, market" componentsSeparatedByString:@", "]];
} else {
NSLog(@"Connection failed: %@", error);
}
}
- (void)dealloc {
[ticker release];
[values release];
[super dealloc];
NSLog(@"Release took place fine");
}
@end
잘 잡았지만'init' 메소드에서'self.ticker = newName'을 사용하지 말 것을 권장합니다. 'ticker = [newName copy]'를 사용하는 것이 더 안전합니다. 이 연습은'ticker'에 대한 속성 접근자를 모두 좀 더 복잡한 것으로 변경하는 경우에 권장됩니다. 잠시 후에 전체 인수에 대한 링크를 찾을 수 있습니다. –
안녕하세요, 빠른 답변에 감사드립니다. 그게 효과가! 그래도 한 가지 질문이 있습니다. 시세 표시를위한 속성에서 (비 원자, 유지). 나는 그것이 newName으로부터 얻은 가치에 대한 트릭을했을 것이라고 생각했다. 티커가 가리키는 newName 객체를 유지해야한다는 말입니까? 티커가 보유 할 속성을 설정하면 그렇게하지 않습니까? – Kirn
자세한 내용은 다른 질문에 대한 내 대답을 살펴보십시오. http://stackoverflow.com/questions/1394360/bad-access-error-even-though-property-is-set-to-retain –