最初の iPhone アプリで分析を実行したところ、潜在的なメモリ リークがいくつか見られました。アプリ自体はシミュレーターで正常に動作します。私は正しいことを行い、潜在的なメモリリークを解消したいと考えていますが、いくつかは非常に不可解です. 多分誰かがここで私を助けることができますか?
前もって感謝します。
橋脚。
エラー 1)アナライザーは、「tempDate および tempAns に格納されているオブジェクトの潜在的なリーク」と言っています。
#import "Answer.h"
@implementation Answer
@synthesize answerTiming;
@synthesize xPosition;
@synthesize earlyOrLate;
@synthesize hit;
+ (Answer *) createAnswerWithTiming :(NSDate *)paramTiming andXPosition :(float) xPosition
{
NSDate * tempDate = [[NSDate alloc] initWithTimeInterval:0 sinceDate:paramTiming];
Answer * tempAns = [[Answer alloc] init ];
[tempAns setAnswerTiming:tempDate];
[tempDate release];
[tempAns setXPosition:xPosition];
[tempAns setEarlyOrLate:0];
[tempAns setHit:false];
return tempAns;
}
- (void)dealloc {
[answerTiming release];
[self release];
[super dealloc];
}
@end
エラー 2)アナライザーの表示 (下記参照)
- (void)viewDidLoad
{
[super viewDidLoad];
........
...
UIImage * perfectImage = [UIImage imageNamed: @"perfect.png"];
self.perfectImageView2 = [[UIImageView alloc]initWithImage:perfectImage];
// メソッドは +1 の保持カウントで目的の C コンテンツを返します
[self.perfectImageView2 setFrame:CGRectMake(145.0f,
150.0f,
self.perfectImageView2.image.size.width,
self.perfectImageView2.image.size.height)];
self.view.backgroundColor = [UIColor whiteColor];
UIImage * levelUpImage = [UIImage imageNamed:@"levelup.png"];
self.levelUpImageView = [[UIImageView alloc] initWithImage:levelUpImage];
[self.levelUpImageView setFrame:CGRectMake(100.0f,
400.0f,
self.levelUpImageView.image.size.width,
self.levelUpImageView.image.size.height)];
//オブジェクトがリークし、割り当てられたオブジェクトはこの実行パスの後半で参照されず、保持カウントが +1 になります
self.view.backgroundColor = [UIColor whiteColor];
}
エラー 3)
- (NSMutableArray *) generateQuestionTapAnswers:(NSString *) answersString withFirstBeat: (NSDate *) firstBeatTime
{
NSArray * notesToDraw = [answersString componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString: @" "]];
float noteValueOffset = 0.0;
NSMutableArray * answerArray = [[NSMutableArray alloc] init ];
// メソッドは +1 の保持カウントを持つ目的の C オブジェクトを返します
for (int i=1; i < notesToDraw.count; i++) // i = 0 is the time signature
{
.....
}
return answerArray;
// 所有参照として呼び出し元に返されたオブジェクト (単一の保持カウントが呼び出し元に転送されます) // オブジェクトのリーク: 割り当てられて answerArray に格納されたオブジェクトは、名前が generateQuestionTapAnswers の名前が copy, mutableCopy で始まらないメソッドから返されます }