简体   繁体   中英

EXC_BAD_ACCESS in obj_msgSend isKindOfClass:

I am getting a crash the second time I attempt to add a certain view as a subview. The crash happens here:

-(void)AddAsScrollableSubContext:(UIView*)view {
    [pExtendedScrollableSubContextBounds addSubview: view]; //CRASH HERE
    pSubScroll.userInteractionEnabled = true;
}

the second time I call...

[mSongContext AddAsScrollableSubContext:pEQRoot];

The flow is something along the lines of

[mSongContext AddAsScrollableSubContext:pEQRoot];
...Load a lot of stuff
...Press a Button
...Unload a lot of stuff
[pEQRoot removeFromSuperview];
...Press a Button
[mSongContext AddAsScrollableSubContext:pEQRoot];

When I get the bad access the callstack looks like the following: 调用栈

Both objects (pExtendedScrollableSubContextBounds and pEQRoot) appear to be valid. Adding other subview to pExtendedScrollableSubContextBounds works fine and calling other operations on pEQRoot (subview, frame) also work.

I read the in objsend r0 was the object and r1 was the selector so I looked at the memory address for r1 and saw...

回忆录

This feels like I am trashing memory somewhere around isKindOfClass: but I am not quite sure. Could anyone point me to more info on iOS obj_msgsend? is there a way I can setup a watch point to catch when this memory trash is occurring?

Use NSZombies to fix the problem.

On a slightly unrelated note, there's a rule of thumb - NARC which stands for new, allocate, retain, copy. If a method call includes any of these keywords, then we have ownership of the object and we are then supposed to release the object.

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