【问题标题】:Potential leak of an object allocated on line ##and stored into musicPlayController在 ## 线上分配并存储到 musicPlayController 中的对象的潜在泄漏
【发布时间】:2012-05-29 12:46:29
【问题描述】:
- (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]; 

不是一个有用的方法。

谢谢你帮助我。

【问题讨论】:

    标签: ios memory-leaks


    【解决方案1】:

    是的,你必须释放musicPlayController

    通过

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

    或者

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

    【讨论】:

    • 如果我发布了 musicPlayController,我的 Play UI 将无法正常工作。我认为现在不是发布的好时机。
    猜你喜欢
    • 2012-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多