[英]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 ? 任何人都可以请他花点时间解释一下
EXC_BAD_ACCESS
异常,而parentVC
和parentVC.audioHandler
和parentVC.audioHandler.player
都存在于内存中吗? ( they all are created with a strong
pointer to them ) (它们都是用指向它们的
strong
指针创建的)
PS: player
is an AVAudioPlayer
and obviously has an isPlaying
method. PS:
player
是AVAudioPlayer
,显然具有isPlaying
方法。
PPS: player
is as same as parentVC.audioHandler.player
and is defined a few lines higher as : PPS:
player
与parentVC.audioHandler.player
相同,并且定义为:
AVAudioPlayer *player = parentVC.audioHandler.player;
Found the problem : 发现问题:
player
is a valid AVAudioPlayer
object and correctly exists in the memory. player
是有效的AVAudioPlayer
对象,并且正确存在于内存中。
The problem is that it is allocated with init
method like : 问题在于它是通过
init
方法分配的,例如:
self.player = [[AVAudioPlayer alloc] init];
Which is wrong because AVAudioPlayer
doesn't have an init
method, you should use initWithURL
or initWithData
instead ! 这是错误的,因为
AVAudioPlayer
没有init
方法,您应该改用initWithURL
或initWithData
!
Hope this can help somebody else. 希望这可以帮助其他人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.