Xcodeでのプログラミングで学校プロジェクトの終わりに近づいていますが、今はちょっとした厄介な問題、つまりメモリリークがあります。リークは、次のコード行まで追跡されています。Xcode 4.2.1:ARCを使用したメモリリークの原因となるNSThread
@autoreleasepool {
[NSThread detachNewThreadSelector:@selector(updateThread) toTarget:self withObject:nil];
}
私がこれをコメントアウトすると、リークはなくなりました。明らかにautoreleasepoolで何かがうまくいかない:私はまだ(特にARCを使用している)これらについて少し新しいですが、this oneのようなスレッドは、@autoreleasepoolを使用すれば十分であるはずです。
何らかの理由で、これは私のコードに当てはまりません。私はここで何かを逃していると思う:誰かが問題の可能性についていくつかのアイデアを与えることができれば、それは高く評価されるだろう。もっとコードを投稿しなければならないかどうか教えてください。それは問題ではありません。問題の可読性だけで、主な問題に限定しようとしています。
ありがとうございます!
EDIT:
は、最初の応答をありがとう!しかし、問題はまだ解決されています...私はちょっとしたことを明確にするためにもう少しコードを投稿します。スレッドは、のviewDidLoadで開始されます。
/*
Everything mentioned here will be done after loading.
*/
- (void)viewDidLoad
{
// Do standard setup
[super viewDidLoad];
// Do any additional setup before loading the view from its nib.
self.title = @"Blog Manager";
// Activate edit mode
[tbvBlogList setEditing:YES animated:YES];
tbvBlogList.allowsSelectionDuringEditing = YES;
[NSThread detachNewThreadSelector:@selector(updateThread) toTarget:self withObject:nil];
UIImage *btnImage = [UIImage imageNamed:@"iPhone_General_Button_Add_Blog.png"];
UIButton *viewBtnAddBlog = [UIButton buttonWithType:UIButtonTypeCustom];
[viewBtnAddBlog setImage:btnImage forState:UIControlStateNormal];
viewBtnAddBlog.frame = CGRectMake(0, 0, 80, 36);
[viewBtnAddBlog addTarget:self action:@selector(addBlogByButton:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnAddBlog = [[UIBarButtonItem alloc] initWithCustomView:viewBtnAddBlog];
btnAddBlog.tintColor = [UIColor clearColor];
self.navigationItem.rightBarButtonItem = btnAddBlog;
}
その後、スレッドのために使用されているその他の機能:
/*
Thread to update the progress bar with.
*/
- (void)updateThread
{
@autoreleasepool {
while(YES){
[self performSelectorOnMainThread:@selector(updateProgressBar) withObject:nil waitUntilDone:false];
[NSThread sleepForTimeInterval:0.1f];
}
}
}
/*
Updates the progress bar.
*/
- (void)updateProgressBar
{
pvProgress.progress = dProgress;
}
それは言及する価値は何である場合:私はXcodeの4.2.1を使用していますが。サポートしてくれてありがとう!
ええ、右:)しかし、あなたはまだ... 1-1 upvoteで行わ:) –
を私たちの答えを尊重することができ、あなたたちはそれに値する:) – Tybs
は、クールおかげで、あなたは最終的にそれを行うことができた嬉しいです。 :) –