简体   繁体   中英

exc_bad_access after obj_msgSend with retainCount = 2

if(currentCat != nil) {
    if ([currentCat hasValidTag]) {...}}

I'm getting an exc_bad_access on second line. retainCount of currentCat is 2 at the moment and there is no autorelease in the stack trace. The code is triggered by an event and executed eleven times without any problems every twelves run fails (I really don`t know why twelve).

My stack trace: 1. obj_msgSend 2. 3. "the calling method" -> ok ...

So as I understand the object exists is not nil. I can`t see any reason for an bad_access. Any idea what happens here .

It's likely that something else in your code is triggering the error - or it may be one of the properties referenced by hasValidTag . Try doing invoking the static analyser through Product > Analyse. If that doesn't work then try the Zombies instrument (Product > Profile).

There is not much to tell about your code, but the exc_bad_access error itself can be a clue to solve your problem.

When you call a message on released objects you get exc_bad_access. You could try to use Instruments with NSZumbie to track your objects and find out why your getting this error.

OBS.: In your code, the first condition

if(currentCat != nil)

is kind of pointless, because the second condition

if ([currentCat hasValidTag])

is enough for checking if currentCat is nil. Calling a message to nil returns nil and do nothing. So the second 'if' block will not be called.

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