在##行上分配的对象的潜在泄漏并存储到musicPlayController中

时间:2012-05-29 12:46:29

标签: ios memory-leaks

- (void)showMusicPlayer
{
[MediaPlayController releaseInstance];
MusicPlayController *musicPlayController = [[MusicPlayController alloc] init];
MusicPlayerViewController *musicPlayerViewController = [musicPlayController createMusicPlayerViewController];

HomeRunManagerAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate showFullScreenView:musicPlayerViewController];
}

Method返回一个带有+1保留计数的object-c对象。

我知道我分配了一个musicPlayController实例,它似乎会播放音乐,但只是漏水。我不知道如何解决警告,(或内存泄漏。) 我应该在哪里释放我的物体?

我想,

MusicPlayController *musicPlayController = [[[MusicPlayController alloc] init] autorelease]; 

不是一种有用的方式。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

是的,您必须发布musicPlayController

通过

MusicPlayController *musicPlayController = [[[MusicPlayController alloc] init] autorelease]; 

或者

 MusicPlayController *musicPlayController = [[MusicPlayController alloc] init];
MusicPlayerViewController *musicPlayerViewController = [musicPlayController createMusicPlayerViewController];  
[musicPlayController release];