私は私のiOSアプリにファイルパスを取得するには、次のコードを持っている:なぜ静的なNSStringは漏れますか?
static const NSString * fullPathFromRelativePath(NSString *relPath)
{
// do not convert a path starting with '/'
if(([relPath length] > 0) && ([relPath characterAtIndex:0] == '/'))
return relPath;
NSMutableArray *imagePathComponents = [NSMutableArray arrayWithArray:[relPath pathComponents]];
NSString *file = [imagePathComponents lastObject];
[imagePathComponents removeLastObject];
NSString *imageDirectory = [NSString pathWithComponents:imagePathComponents];
NSString *fullpath = [[NSBundle mainBundle] pathForResource:file
ofType:NULL
inDirectory:imageDirectory];
if (!fullpath)
fullpath = relPath;
return fullpath;
}
static const char * fullCPathFromRelativePath(const char *cPath)
{
NSString *relPath = [NSString stringWithCString:cPath encoding:NSUTF8StringEncoding];
const NSString *path = fullPathFromRelativePath(relPath);
const char *c_path = [path UTF8String];
return c_path;
}
static const char * relativeCPathForFile(const char *fileName)
{
NSString *relPath = [NSString stringWithCString:fileName encoding:NSUTF8StringEncoding];
const NSString *path = fullPathFromRelativePath(relPath);
const char *c_path = [[path stringByDeletingLastPathComponent] UTF8String];
return c_path;
}
私がデバッグコンソールでは、このようなかなりの数のメッセージを取得しています:
objc[4501]: Object 0x6e17060 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[4501]: Object 0x6e12470 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[4501]: Object 0x6e12580 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
に問題は何コード? (私はiOS 5を "自動"保持/解放などで使用しています)
乾杯。
ねえ、この答えは正しいです。私はココアのAPIを介してより多くのスレッドを作成していなかったが、いくつかの新しいスレッドは、この問題の原因は、低レベルのC関数で作成されていた。私は@autoreleasepoolの周りに最初のメソッドをラップし、問題は修正されました。 まだARCの周りに私の頭を包んで:) – Goles