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

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

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

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

我认为,

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

不是一个有用的方法。

谢谢你帮助我。

4

1 回答 1

0

是的,你必须释放musicPlayController

或者通过

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

或者

 MusicPlayController *musicPlayController = [[MusicPlayController alloc] init];
MusicPlayerViewController *musicPlayerViewController = [musicPlayController createMusicPlayerViewController];  
[musicPlayController release];
于 2012-05-29T12:59:15.977 回答