得到消息只是泄漏记忆

时间:2011-05-12 05:45:22

标签: iphone objective-c

嗨朋友我在控制台上有消息(它没有给出错误或警告)它只显示消息 消息就像那样

 __NSAutoreleaseNoPool(): Object 0x6378190 of class HGMapPath autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x6379e00 of class HGMovingAnnotation autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x578f2e0 of class __NSCFSet autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x5790a00 of class __NSDate autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x5790ab0 of class __NSCFTimer autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x6348c90 of class UIView autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x633fb60 of class UILayoutContainerView autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x6379c10 of class __NSArrayI autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790e20 of class MKDirectionsRouteInfo autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x6371a40 of class MKDirectionsRouteInfo autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x63799c0 of class NSCFString autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x6371e30 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x636d850 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790cf0 of class __NSArrayI autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790d10 of class __NSArrayI autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790e90 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790d30 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790d40 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790d50 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790d60 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790d70 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790d80 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790d90 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x6379b40 of class __NSArrayI autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x6375300 of class CABasicAnimation autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790b40 of class CABasicAnimation autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790ed0 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x5790ee0 of class NSCFNumber autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x634d210 of class CABasicAnimation autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x6379b60 of class CABasicAnimation autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x637b870 of class __NSCFDictionary autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x6371960 of class NSThread autoreleased with no pool in place - just leaking

我只是想知道它为什么会发生。它是否会在未来产生问题。我该如何解决?

我正在使用此代码请查看它并建议我解决此问题的最佳方法。

//start tracking vehicle locations. In DEMO mode just read locations from the path...
- (void) start
{
  [self performSelectorInBackground:@selector(startTracking) withObject:nil];
}

- (void) stop 
{
  [NSObject cancelPreviousPerformRequestsWithTarget:self];
  self.isMoving = NO;
}


- (void) startTracking
{
    self.isMoving = YES; 

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  for(int i=_currentPathPointIndex+1; i<path.pointCount; i++)
  {

    currentLocation = self.path.points[i]; 

    _distanceTravelled += MKMetersBetweenMapPoints(self.path.points[i], self.path.points[i-1]);

      //send notification
      [[NSNotificationCenter defaultCenter] postNotificationName:kObjectMovedNotification object:self]; 

      [NSThread sleepForTimeInterval : DEMO_SPEED];
  }

  //finished moving along the path - send notification
  [[NSNotificationCenter defaultCenter] postNotificationName:kObjectRechedEndOfPathNotification object:self]; 

  [pool drain];
}

提前致谢

1 个答案:

答案 0 :(得分:15)

当获取“no pool in place error”时,在进程启动时将调试器集环境变量NSAutoreleaseHaltOnNoPool设置为YES。这将导致调试器在发出其中一条消息时中断。此时,callstack应该帮助您确定需要添加自动释放池的位置。

有关NSAutoreleaseHaltOnNoPool和许多其他调试工具的信息,可以在NSDebug.h中找到。