JSONValue显示内存泄漏

时间:2012-10-04 07:27:47

标签: iphone json sbjson

-(void)loadMakes:(NSString *)strValue
{
  NSDictionary *makeJSON = [strValue JSONValue];
  NSDictionary *makes = NULL;
  NSDictionary *car = NULL;
  NSArray *keys = NULL;
  NSMutableArray *tempCar = [[NSMutableArray alloc]init];
  if ([makeJSON count] != 0)
  {
    makes = [makeJSON objectForKey:@"makes"];
    keys=[[makes allKeys]sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

    for(int i=0; i<[makes count]; i++)
    {
      car = [makes objectForKey:[keys objectAtIndex:i]];
      CarMake *carMakeObj = [[CarMake alloc]init];
      [carMakeObj setCarName:[car objectForKey:@"name"]];
      [carMakeObj setCarLinks:[car objectForKey:@"link"]];
      //[carMakeObj Print];
      [tempCar addObject:carMakeObj];
      [carMakeObj release];
    }

    self.carNamesArrayList=tempCar;
    [tempCar release];
   }
  NSLog(@"count %d",[carNamesArrayList count]);
}

我在-viewDidAppear中调用了上面的代码,并且在第一次出现视图时它没有显示任何泄漏。但是当我按下BACK按钮并再次单击视图时,仪器显示泄漏

  NSDictionary *makeJSON=[strValue JSONValue];

然后我添加了

  [makeJSON release];
  makeJSON = nil;

但我得到了错误

  ****-[CFDictionary release]: message sent to deallocated instance

然后我添加了

  NSDictionary *makeJSON=[[strValue JSONValue]retain];

我再次得到这样的错误

  ****-[CFDictionary release]: message sent to deallocated instance

此外,我打印 **保留计数的makeJSON ,它显示2

需要帮助!!!!!请说出错的地方

1 个答案:

答案 0 :(得分:0)

你检查了这条线的删除

 [makeJSON release];

Bcoz你没有分配这个对象,或者你要发布这个对象,因为它给出了这种类型的错误。