我有以下的(改編自蘋果低級別文件管理 - 解決別名)Core Foundation的對象 - 潛在的泄漏
NSString *resolvedPath = nil;
...
resolvedPath = (NSString*)CFURLCopyFileSystemPath(resolvedUrl, kCFURLPOSIXPathStyle);
...
return resolvedPath;
構建&分析生成以下警告: -
194:3 Potential leak (when using garbage collection) of an object allocated on line 187 and stored into 'resolvedPath'
細節狀態: -
187:32 Call to function 'CFURLCopyFileSystemPath' returns a Core Foundation object with a +1 retain count (owning reference). Core Foundation objects are not automatically garbage collected
194:3 Object returned to caller as an owning reference (single retain count transferred to caller)
194:3 Object allocated on line 187 and stored into 'resolvedPath' and returned from method 'getTarget:' is potentially leaked when using garbage collection. Callers of this method do not expect a returned object with a +1 retain count since they expect the object to be managed by the garbage collector
是否有內存泄漏?
如果讓我怎麼解決?
如果不是我應該如何防止警告?
謝謝,NSMakeCollectable似乎已經做的工作。遺憾的是,在文檔中很難找到這些概念,但一旦發現就很明顯。 – Milliways