简体   繁体   中英

EXC_BAD_ACCESS with Code=2 While Objects Exist In Memory

Can anybody kindly take his time and explain how it is possible to get such EXC_BAD_ACCESS exception while parentVC & parentVC.audioHandler & parentVC.audioHandler.player all do exist in memory ? ( they all are created with a strong pointer to them )

在此处输入图片说明

PS: player is an AVAudioPlayer and obviously has an isPlaying method.

PPS: player is as same as parentVC.audioHandler.player and is defined a few lines higher as :

AVAudioPlayer *player = parentVC.audioHandler.player;

Found the problem :

player is a valid AVAudioPlayer object and correctly exists in the memory.

The problem is that it is allocated with init method like :

self.player = [[AVAudioPlayer alloc] init];

Which is wrong because AVAudioPlayer doesn't have an init method, you should use initWithURL or initWithData instead !

Hope this can help somebody else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM