Troubleshoot a potential memory leak in ARC

The following helper method, singleton class (SharedManager), can trigger a save loop. Getting warnings in the static analyzer: "Potential leak of the object highlighted in the string ..." How can I fix it?

I tried to do ivar uuid __weak, but a warning still appears during parsing.

NSString *__weak uuid = (__bridge NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObject); 

thanks

Called in a class as follows:

 myUUID = [SharedManager generateUUID]; + (NSString *)generateUUID { CFUUIDRef uuidObject = CFUUIDCreate(kCFAllocatorDefault); NSString *uuid = (__bridge NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObject); CFRelease(uuidObject); return uuid; } 
+6
source share
2 answers
 NSString *uuid = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObject); 

Does this remove the warning?

+6
source

Here is a way to release them:

 - (NSString *) uuid { CFUUIDRef uuidRef = CFUUIDCreate(NULL); CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); CFRelease(uuidRef); NSString *uuid = [NSString stringWithString:(NSString *) uuidStringRef]; CFRelease(uuidStringRef); return uuid; } 

Source: http://www.cocoabuilder.com/archive/cocoa/217665-how-to-create-guid.html

+7
source

Source: https://habr.com/ru/post/911148/


All Articles