2011-08-05 51 views
0

我有以下兩種方法:IOS:泄漏警告不明確

-(void)playSound { 
    NSString* filePath = [self getBasePath]; // <-- warnings appear when this is called 
} 

-(NSString*) getBasePath { 
    if(debug) NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__); 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES); 
     NSString *documentsDir = [paths objectAtIndex:0]; 

    if(debug) NSLog(@">>> Leaving %s <<<", __PRETTY_FUNCTION__); 
    return documentsDir; 
} 

調用playsound的梅索德getBasePath被調用時。但後來我在控制檯上得到以下警告:

2011-08-06 00:26:56.298 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e350e0 of class __NSArrayM autoreleased with no pool in place - just leaking 
2011-08-06 00:26:56.299 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e350c0 of class NSCFString autoreleased with no pool in place - just leaking 
2011-08-06 00:26:56.300 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4b43c00 of class NSCFString autoreleased with no pool in place - just leaking 
2011-08-06 00:26:56.300 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4b46900 of class NSPathStore2 autoreleased with no pool in place - just leaking 
2011-08-06 00:26:56.301 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e37630 of class NSPathStore2 autoreleased with no pool in place - just leaking 
2011-08-06 00:26:56.302 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e35100 of class __NSArrayI autoreleased with no pool in place - just leaking 

這是什麼意思?

回答

3

也許你正在執行此方法不在主線程。如果你這樣做,你必須創建一個NSAutoreleasePool。

-(void)playSound { 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    int index = rand() % [soundFilenames count]; 
    NSString* filePath = [self getBasePath]; 
    [pool drain]; 
} 
+0

謝謝,實際上是這樣。 – toom