消息发送到已释放的对象(从不手动释放)

发布于 2024-11-18 10:49:02 字数 1137 浏览 3 评论 0原文

删除了发布声明。其中一些看起来还不错,但这可能只是因为其他事情先爆炸了。


- (void)handleNowPlayingItemChanged:(id)notification {
    MPMediaItem *item = self.musicPlayer.nowPlayingItem;
    NSString *title = [item valueForProperty:MPMediaItemPropertyTitle];

    NSNumber *duration = [item
                         valueForProperty:MPMediaItemPropertyPlaybackDuration];
    float totalTime = [duration floatValue];
    progressSlider.maximumValue = totalTime;

    CGSize artworkImageViewSize = self.albumCover.bounds.size;
    MPMediaItemArtwork *artwork = [item valueForProperty:
                                                   MPMediaItemPropertyArtwork];
    if (artwork) {
        self.albumCover.image = [artwork imageWithSize:artworkImageViewSize];
    } else {
        self.albumCover.image = nil;
    }

    titleLabel.text = title;

    /*OpenEars stuff*/
}

另一个问题中,我提到了有关艺术作品的 SQLite 错误。

** 删除了有关调用已释放对象的 NSZombieEnabled 警报的错误和详细信息。 **


好吧,我不觉得自己很蠢。这都是内存管理。
我努力不泄露任何东西,即使是临时解决方案,但我还是这么做了……

Removed release statements. Some of them seemed to be okay, but that was probably just because other things were exploding first.


- (void)handleNowPlayingItemChanged:(id)notification {
    MPMediaItem *item = self.musicPlayer.nowPlayingItem;
    NSString *title = [item valueForProperty:MPMediaItemPropertyTitle];

    NSNumber *duration = [item
                         valueForProperty:MPMediaItemPropertyPlaybackDuration];
    float totalTime = [duration floatValue];
    progressSlider.maximumValue = totalTime;

    CGSize artworkImageViewSize = self.albumCover.bounds.size;
    MPMediaItemArtwork *artwork = [item valueForProperty:
                                                   MPMediaItemPropertyArtwork];
    if (artwork) {
        self.albumCover.image = [artwork imageWithSize:artworkImageViewSize];
    } else {
        self.albumCover.image = nil;
    }

    titleLabel.text = title;

    /*OpenEars stuff*/
}

In another question I mention the SQLite errors concerning artwork.

** Deleted error and details concerning NSZombieEnabled alert of call to released objects. **


Well don't I feel stupid. It was all memory management.
I put effort into not leaking anything, even in a temporary solution, and yet I did this...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不可一世的女人 2024-11-25 10:49:02

在您提供的代码中,我没有看到任何对保留、分配/初始化或复制的某些变体的调用。这意味着您不应该在该方法中调用任何release,这将是导致崩溃的原因。确保您没有以其他方法过度释放并记住 内存管理基础

In the code you provide I do not see any calls to retain, alloc/init, or some variation of copy. That means that you should not have a any calls to release in that method and that will be the cause of your crash. Make sure you are not over releasing in other methods and remember the basics of memory management.

吃颗糖壮壮胆 2024-11-25 10:49:02

您正在发布标题和艺术作品,但它们不是您的。这迟早会导致尝试释放已经释放的对象(从项目的释放或其他地方)。

You're releasing title and artwork, but they're not yours. This will lead, soon or later, to a tentative to release an already deallocated object (from item's dealloc or somewhere else).

似最初 2024-11-25 10:49:02

// [艺术品发布];

//[标题发布];

评论那些因为那些是自动释放的对象

// [artwork release];

//[title release];

comment those since those are autoreleased object

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文