EXC_BAD_ACCESS signal received

前端 未结 30 3100
轮回少年
轮回少年 2020-11-22 06:37

When deploying the application to the device, the program will quit after a few cycles with the following error:

Program received signal: \"EXC_BAD_ACCESS\".         


        
30条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 06:51

    Not a complete answer, but one specific situation where I've received this is when trying to access an object that 'died' because I tried to use autorelease:

    netObjectDefinedInMyHeader = [[[MyNetObject alloc] init] autorelease];
    

    So for example, I was actually passing this as an object to 'notify' (registered it as a listener, observer, whatever idiom you like) but it had already died once the notification was sent and I'd get the EXC_BAD_ACCESS. Changing it to [[MyNetObject alloc] init] and releasing it later as appropriate solved the error.

    Another reason this may happen is for example if you pass in an object and try to store it:

    myObjectDefinedInHeader = aParameterObjectPassedIn;
    

    Later when trying to access myObjectDefinedInHeader you may get into trouble. Using:

    myObjectDefinedInHeader = [aParameterObjectPassedIn retain];
    

    may be what you need. Of course these are just a couple of examples of what I've ran into and there are other reasons, but these can prove elusive so I mention them. Good luck!

提交回复
热议问题