1

메모리 누수 찾기는 내게 적합하지 않지만 악기가 NSMutableDictionary를 만들거나 값을 설정할 때 메모리 누수를 나타냅니다. (저는 ARC를 사용하고 있습니다). 이것은 아직 이해가되지 않습니다. 누군가가 실제로 무슨 일이 일어나고 있는지 알기를 바랍니다.인스트루먼트는 NSMutableDictionary의 인스턴스화시 메모리 누수를 나타냅니다.

저는 장치의 카메라로 사진을 촬영할 때 호출되는 대리자 메서드가 있습니다. 문제를 제기하는 선에 대한 주석을 추가했습니다. objectOrNull 우리가 삽입되는 값이 존재하는지 확인하고, 그렇지 않으면 [NSNull 널] 사전에 추가

- (void)finishImageCaptureForBuffer:(CMSampleBufferRef)imageDataSampleBuffer withError:(NSError *)error shouldSave:(BOOL)save 
{ //do some stuff... 

if (save) { 
    CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, 
                   self.imageDataSampleBuffer, 
                   kCMAttachmentMode_ShouldPropagate); 
    CFMutableDictionaryRef mutableAttachments = CFDictionaryCreateMutableCopy(NULL, 0, attachments); 

    //MEMORY LEAK!!!!!// 
    NSMutableDictionary *gps = [NSMutableDictionary dictionary]; 

    CLLocation *location = [manager location]; 
    [gps setObject:@"" forKey:(NSString *)kCGImagePropertyGPSVersion]; 

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
    [formatter setDateFormat:@"HH:mm:ss.SSSSSS"]; 
    [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; 

    //MEMORY LEAK!!!!!// 
    [gps setObject:ObjectOrNull([formatter stringFromDate:location.timestamp]) 
      forKey:(NSString *)kCGImagePropertyGPSTimeStamp]; 

    [gps setObject:(location.coordinate.latitude < 0) ? @"S" : @"N" 
      forKey:(NSString *)kCGImagePropertyGPSLatitudeRef]; 

    //MEMORY LEAK!!!!! 
    [gps setObject:ObjectOrNull([NSNumber numberWithDouble:fabs(location.coordinate.latitude)]) 
      forKey:(NSString *)kCGImagePropertyGPSLatitude]; 

    [gps setObject: (location.coordinate.longitude < 0) ? @"W" : @"E" 
      forKey:(NSString *)kCGImagePropertyGPSLongitudeRef]; 

    //MEMORY LEAK!!! 
    [gps setObject:ObjectOrNull([NSNumber numberWithDouble:fabs(location.coordinate.longitude)]) 
      forKey:(NSString *)kCGImagePropertyGPSLongitude]; 

    CFDictionarySetValue(mutableAttachments, kCGImagePropertyGPSDictionary, CFBridgingRetain(gps)); 

    NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:self.imageDataSampleBuffer]; 
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 

    [library writeImageDataToSavedPhotosAlbum:imageData 
            metadata:(__bridge id)mutableAttachments 
           completionBlock:completionBlock]; 

    if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)]) { 
     [[self delegate] captureManagerStillImageCaptured:self]; 
    } 

    CFRelease(attachments); 
    CFRelease(mutableAttachments); 
    CFRelease(self.imageDataSampleBuffer); 

} else { ... 

.

iOS7은 실행하지만 iOS8은 실행하지 않는 경우이 문제가 발생합니다. 내가 만약 한 Statment의 말미에 추가 할 때

답변

0

CFDictionarySetValue(mutableAttachments, kCGImagePropertyGPSDictionary, (__bridge CFDictionaryRef)gps); 
+0

감사와

CFDictionarySetValue(mutableAttachments, kCGImagePropertyGPSDictionary, CFBridgingRetain(gps)); 

를 교체하십시오, 이것은 또한 일 : CFRelease ((__ 다리 CFTypeRef) (GPS)); – jac300

관련 문제