我只是想知道是否有人可以向我解释为什么以下行显示为仪器内存泄漏:
self.videoEngine = [[VideoEngine alloc] initWithCallbackName:@"IntroFinished"];
self.videoEngine = [[VideoEngine alloc] initWithCallbackName:@"MainMovieFinished"];
self.timerMap = [NSTimer scheduledTimerWithTimeInterval:fps target:self selector:@selector(updateAnimationTimer) userInfo:nil repeats:YES];
NSString *locationName2 = [[NSString alloc] initWithString:[locationName substringFromIndex:test]];
初始化时是否存在未使用预设NSString的问题?在self.videoEngine和self.timerMap的示例中,它们都具有(非原子,保留)属性,并在使用前进行合成。
答案 0 :(得分:3)
如果你没有使用Arc(其中提到了保留,我认为你没有)那么那将是你的内存泄漏。
分配VideoEngine属性时,它会在您的对象上执行另一次保留。您需要添加自动释放到结束语句。
self.videoEngine = [[[VideoEngine alloc] initWithCallbackName:@"IntroFinished"] autorelease];
self.videoEngine = [[[VideoEngine alloc] initWithCallbackName:@"MainMovieFinished"] autorelease];
self.timerMap = [NSTimer scheduledTimerWithTimeInterval:fps target:self selector:@selector(updateAnimationTimer) userInfo:nil repeats:YES];
NSString *locationName2 = [[NSString alloc] initWithString:[locationName substringFromIndex:test]];