2 초마다 JSON 데이터를 가져 와서 처리를 위해 다른 클래스에 전달하려고하면 모든 것이 제대로 작동하지만 아래 코드는 (Instruments의) 메모리 누수가있는 것 같지만 무엇인지 알아 내지 못합니다. 잘못 고칠 수있는 방법, 누군가 제발 할 수있는 조언을 ???YAJL 메모리 누수 문제 배열
* 전체 논리를 업데이트하며 누수되는 주요 방법에 전달 된 배열처럼 보이는 계기가 거짓보고 YAJL 누출로 .. (아주 확실하지 네가) * 그 인스트루먼트
@property (nonatomic,retain,readwrite) NSMutableArray *deviceListArray;
- (void)viewDidLoad
{
[super viewDidLoad];
deviceListArray=[[NSMutableArray alloc]init];
[self init];
TestClass *initiateData = [GetData alloc]init];
[initiateData startTimer];
[initiateData release];
}
- (id) init{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveDeviceListNotification:)
name:@"devicelist"
object:nil];
}
- (void) receiveDeviceListNotification:(NSNotification *) notification{
deviceListArray=[notification object];
[deviceListTable reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [deviceListArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[deviceListArray retain]; //CRASHES WITHOUT RETAIN specified here
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.textColor = [UIColor redColor];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
[cell.textLabel setText:[deviceListArray objectAtIndex:indexPath.row]]; //CRASHES if i remove the retain on devicelistarray
return cell;
}
@class TestClass;
@implementation TestClass
- (void)startTimer:(NSString *)timerstring
{
if(timerstring [email protected]"StartNow")
{
NSLog(@"Timer started");
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(TestMethod:) userInfo:nil repeats:YES];
}
else{
NSLog(@"string not received");
}
}
-(void)TestMethod:(NSTimer *)Timer {
NSTimeInterval timeNow= [NSDate timeIntervalSinceReferenceDate];
NSData *JSONData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.example/data.json"]];
NSArray *testArray=[JSONData yajl_JSON]; //MEMORY LEAK HERE
if(testArray==nil)
{
NSLog(@"Array is nil");
}
else
{
NSArray *arrayNumberOne=[[testArray valueForKey:@"devicelist"]objectAtIndex:0];
NSArray *arrayNumberTwo=[testArray valueForKey:@"arrayNumberTwo"];
NSArray *arrayNumberThree=[testArray valueForKey:@"arrayNumberThree"];
float dowloadY=[[arrayNumberTwo objectAtIndex:0]floatValue];
float uploadY=[[arrayNumberThree objectAtIndex:0]floatValue];
NSDictionary *newarrayNumberTwoData= [NSDictionary dictionaryWithObjectsAndKeys:
[NSDecimalNumber numberWithInt:timeNow], [NSNumber numberWithInt:0],
[NSDecimalNumber numberWithFloat:dowloadY], [NSNumber numberWithInt:1],nil
] ;
NSDictionary *newarrayNumberThreeData= [NSDictionary dictionaryWithObjectsAndKeys:
[NSDecimalNumber numberWithInt:timeNow], [NSNumber numberWithInt:0],
[NSDecimalNumber numberWithFloat:uploadY], [NSNumber numberWithInt:1],nil
] ;
[[NSNotificationCenter defaultCenter] postNotificationName:@"devicelist" object:arrayNumberOne];
[[NSNotificationCenter defaultCenter] postNotificationName:@"TestData2" object:newarrayNumberTwoData];
[[NSNotificationCenter defaultCenter] postNotificationName:@"TestData3" object:newarrayNumberThreeData];
}
}
-(void) dealloc{
[super dealloc];
}
@end
메모리 누수 로그는 간단 보인다, 잘
Leaked Object # Address Size Responsible Library Responsible Frame __NSArrayM,569 <multiple> 17.78 KB MYTESTAPP3 -[YAJLDocument parserDidStartArray:] Malloc 80 Bytes,480 <multiple> 37.50 KB MYTESTAPP3 -[YAJLDocument parserDidStartArray:] NSCFString,397 <multiple> 11.44 KB Foundation -[NSPlaceholderString initWithBytes:length:encoding:] NSCFString, 0x4c1dac0 32 Bytes Foundation -[NSPlaceholderString initWithBytes:length:encoding:]
두 개의 yajl이 있습니다 - 하나는 C (하스켈 바인딩이 있음)와 하나가 Ruby에 있습니다. 그래서 나는이 루비에 태그를 붙였습니다. –
Instrument (Instrument) 란 무엇입니까? –
@Andrew Grimm 저는 Xcode Link에서 "Instruments"를 사용하고 있습니다 : http : //developer.apple.com/technologies/tools/ – Linus