{"rsdb":{"rid":"380798","subhead":"","postdate":"0","aid":"266007","fid":"99","uid":"1","topic":"1","content":"
\n

\"52f57b4ab65a9t1280l75.jpg\"<\/p> \n

\u539f\u6587\uff1aWhat Is EXC_BAD_ACCESS and How to Debug It<\/a><\/p> \n

\u6709\u65f6\u5019\uff0c\u4f60\u4f1a\u9047\u5230\u7531EXC_BAD_ACCESS\u9020\u6210\u7684\u5d29\u6e83\u3002 \u8fd9\u7bc7\u6587\u7ae0\u4f1a\u544a\u8bc9\u4f60\u4ec0\u4e48\u662fEXC_BAD_ACCESS\uff0c\u4ee5\u53ca\u5b83\u4ea7\u751f\u7684\u539f\u56e0\u3002\u6211\u8fd8\u4f1a\u63d0\u4f9b\u4e00\u4e9bEXC_BAD_ACCESS\u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p> \n

1. \u4ec0\u4e48\u662f EXC_BAD_ACCESS?<\/p> \n

\u4e00\u65e6\u4f60\u7406\u89e3EXC_BAD_ACCESS\u7684\u672c\u8d28\uff0c\u4f60\u5c31\u4f1a\u66f4\u597d\u5730\u7406\u89e3\u8fd9\u4e2a\u6a21\u7cca\u7684\u540d\u8bcd\u3002\u8fd9\u91cc\u6709\u4e00\u4e2a\u6781\u4e3a\u7b80\u5355\u7684\u89e3\u91ca\uff0c\u4e5f\u6709\u4e00\u4e2a\u6280\u672f\u5c42\u9762\u7684\u89e3\u91ca\u3002\u6211\u4eec\u9996\u5148\u4ece\u7b80\u5355\u7684\u89e3\u91ca\u5f00\u59cb\u8bf4\u8d77\u3002<\/p> \n

2. \u7b80\u5355\u7684\u89e3\u91ca<\/p> \n

\u4e0d\u7ba1\u4ec0\u4e48\u65f6\u5019\u5f53\u4f60\u9047\u5230EXC_BAD_ACCESS\u8fd9\u4e2a\u9519\u8bef\uff0c\u90a3\u5c31\u610f\u5473\u7740\u4f60\u5411\u4e00\u4e2a\u5df2\u7ecf\u91ca\u653e\u7684\u5bf9\u8c61\u53d1\u9001\u6d88\u606f\u3002\u8fd9\u662f\u6700\u5e38\u89c1\u7684\u60c5\u51b5\uff0c\u4f46\u4e5f\u6709\u4f8b\u5916\uff0c\u6211\u4eec\u5c06\u5728\u7a0d\u540e\u8ba8\u8bba\u3002<\/p> \n

3. EXC_BAD_ACCESS\u7684\u672c\u8d28<\/p> \n

\u6280\u672f\u5c42\u9762\u7684\u89e3\u91ca\u6709\u4e9b\u590d\u6742\u3002\u5728C\u548cObjective-C\u4e2d\uff0c\u4f60\u4e00\u76f4\u5728\u5904\u7406\u6307\u9488\u3002\u6307\u9488\u65e0\u975e\u662f\u5b58\u50a8\u53e6\u4e00\u4e2a\u53d8\u91cf\u7684\u5185\u5b58\u5730\u5740\u7684\u53d8\u91cf\u3002\u5f53\u60a8\u5411\u4e00\u4e2a\u5bf9\u8c61\u53d1\u9001\u6d88\u606f\u65f6\uff0c\u6307\u5411\u8be5\u5bf9\u8c61\u7684\u6307\u9488\u5c06\u4f1a\u88ab\u5f15\u7528\u3002\u8fd9\u610f\u5473\u7740\uff0c\u4f60\u83b7\u53d6\u4e86\u6307\u9488\u6240\u6307\u7684\u5185\u5b58\u5730\u5740\uff0c\u5e76\u8bbf\u95ee\u8be5\u5b58\u50a8\u533a\u57df\u7684\u503c\u3002<\/p> \n

\u5f53\u8be5\u5b58\u50a8\u5668\u533a\u57df\u4e0d\u518d\u6620\u5c04\u5230\u60a8\u7684\u5e94\u7528\u65f6\uff0c\u6216\u8005\u6362\u53e5\u8bdd\u8bf4\uff0c\u8be5\u5185\u5b58\u533a\u57df\u5728\u4f60\u8ba4\u4e3a\u4f7f\u7528\u7684\u65f6\u5019\u5374\u6ca1\u6709\u4f7f\u7528\uff0c\u8be5\u5185\u5b58\u533a\u57df\u662f\u65e0\u6cd5\u8bbf\u95ee\u7684\u3002 \u8fd9\u65f6\u5185\u6838\u4f1a\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38\uff08 EXC \uff09\uff0c\u8868\u660e\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u4e0d\u80fd\u8bbf\u95ee\u8be5\u5b58\u50a8\u5668\u533a\u57df\uff08BAD ACCESS\uff09 \u3002<\/p> \n

\u603b\u4e4b\uff0c\u5f53\u4f60\u78b0\u5230EXC_BAD_ACCESS \uff0c\u8fd9\u610f\u5473\u7740\u4f60\u8bd5\u56fe\u53d1\u9001\u6d88\u606f\u5230\u7684\u5185\u5b58\u5757\uff0c\u4f46\u5185\u5b58\u5757\u65e0\u6cd5\u6267\u884c\u8be5\u6d88\u606f\u3002\u4f46\u662f\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c EXC_BAD_ACCESS\u662f\u7531\u88ab\u635f\u574f\u7684\u6307\u9488\u5f15\u8d77\u7684\u3002\u6bcf\u5f53\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u5c1d\u8bd5\u5f15\u7528\u635f\u574f\u7684\u6307\u9488\uff0c\u4e00\u4e2a\u5f02\u5e38\u5c31\u4f1a\u88ab\u5185\u6838\u629b\u51fa\u3002<\/p> \n

4.\u8c03\u8bd5EXC_BAD_ACCESS<\/p> \n

\u8c03\u8bd5EXC_BAD_ACCESS\u53ef\u80fd\u4f1a\u975e\u5e38\u68d8\u624b\u548c\u4ee4\u4eba\u6cae\u4e27\u3002\u7136\u800c\uff0c\u73b0\u5728EXC_BAD_ACCESS\u4e0d\u518d\u662f\u4e00\u4e2a\u8c1c\uff0c\u5b83\u6ca1\u6709\u60f3\u8c61\u4e2d\u7684\u90a3\u4e48\u53ef\u6015\u3002<\/p> \n

\u4f60\u9700\u8981\u77e5\u9053\u7684\u7b2c\u4e00\u4ef6\u4e8b\u662f\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u5e76\u4e0d\u4e00\u5b9a\u662f\u5728\u5d29\u6e83\u7684\u90a3\u4e00\u523b\uff0c\u65e0\u6cd5\u8bbf\u95ee\u5185\u5b58\u533a\u57df\u3002\u8fd9\u5c31\u662f\u5e38\u4f7f\u8c03\u8bd5EXC_BAD_ACCESS\u53d8\u5f97\u56f0\u96be\u7684\u539f\u56e0\u3002<\/p> \n

\u540c\u6837\u53d7\u635f\u6307\u9488\u4e5f\u662f\u5982\u6b64\u3002\u5f53\u4f60\u7684\u6307\u9488\u88ab\u635f\u574f\u65f6\uff0c\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u4e0d\u4f1a\u5d29\u6e83\u3002\u540c\u65f6\uff0c\u5982\u679c\u60a8\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u6765\u56de\u4f20\u9012\u4e00\u4e2a\u53d7\u635f\u7684\u6307\u9488\u4e5f\u4e0d\u4f1a\u5d29\u6e83\u3002\u5f53\u5e94\u7528\u7a0b\u5e8f\u8bd5\u56fe\u5f15\u7528\u53d7\u635f\u6307\u9488\u7684\u65f6\u5019\uff0c\u5c31\u4f1a\u53d1\u751f\u5954\u6e83\u3002<\/p> \n

5.\u50f5\u5c38\u8c03\u8bd5\u6a21\u5f0f<\/p> \n

\u50f5\u5c38\u8c03\u8bd5\u6a21\u5f0f\u5728\u8fc7\u53bb\u51e0\u5e74\u4e2d\u5f97\u5230\u4e86\u666e\u53ca\uff0c\u4e8b\u5b9e\u4e0a\u5b83\u4eec\u5df2\u7ecf\u51fa\u73b0\u5728Xcode\u4e0a\u8d85\u8fc7\u5341\u5e74\u3002\u50f5\u5c38\u542c\u8d77\u6765\u6709\u70b9\u620f\u5267\u6027\uff0c\u4f46\u5b83\u5b9e\u9645\u4e0a\u662f\u4e3a\u5e2e\u52a9\u6211\u4eec\u8c03\u8bd5EXC_BAD_ACCESS\u529f\u80fd\u800c\u53d6\u5f97\u4e00\u4e2a\u4f1f\u5927\u7684\u540d\u5b57\u3002\u8ba9\u6211\u6765\u89e3\u91ca\u5b83\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002<\/p> \n

\u5728Xcode\u4e2d\uff0c\u60a8\u53ef\u4ee5\u542f\u7528\u50f5\u5c38\u5bf9\u8c61\uff0c\u8fd9\u610f\u5473\u7740\u88ab\u91ca\u653e\u7684\u5bf9\u8c61\u5c06\u4f1a\u4ee5\u50f5\u5c38\u7684\u5f62\u5f0f\u88ab\u4fdd\u7559\u3002\u6362\u8a00\u4e4b\uff0c\u4fdd\u7559\u91ca\u653e\u7684\u5bf9\u8c61\u5c31\u662f\u4e3a\u4e86\u8c03\u8bd5\u3002\u8fd9\u91cc\u6ca1\u6709\u6d89\u53ca\u4efb\u4f55\u9b54\u6cd5\u3002\u5982\u679c\u60a8\u5411\u50f5\u5c38\u5bf9\u8c61\u53d1\u9001\u6d88\u606f\uff0c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u5c06\u4f1a\u7531\u4e8eEXC_BAD_ACCESS\u800c\u5d29\u6e83\u3002<\/p> \n

\u8fd9\u6709\u4ec0\u4e48\u597d\u5904\u5417\uff1f\u8ba9EXC_BAD_ACCESS\u96be\u4ee5\u8c03\u8bd5\u7684\u539f\u56e0\u662f\uff0c\u4f60\u4e0d\u77e5\u9053\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u8bd5\u56fe\u8bbf\u95ee\u54ea\u4e2a\u5bf9\u8c61\u3002\u50f5\u5c38\u5bf9\u8c61\u5728\u8bb8\u591a\u60c5\u51b5\u4e0b\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u901a\u8fc7\u4fdd\u7559\u5df2\u91ca\u653e\u7684\u5bf9\u8c61\uff0cXcode\u53ef\u4ee5\u544a\u8bc9\u4f60\u4f60\u8bd5\u56fe\u8bbf\u95ee\u54ea\u4e2a\u5bf9\u8c61\uff0c\u8fd9\u4f7f\u7684\u67e5\u627e\u95ee\u9898\u539f\u56e0\u5bb9\u6613\u5f97\u591a\u3002<\/p> \n

\u5728Xcode\u4e2d\u542f\u7528\u50f5\u5c38\u5bf9\u8c61\u662f\u5f88\u5bb9\u6613\u7684\u3002\u6ce8\u610f\uff0c\u8fd9\u53ef\u80fd\u4f1a\u56e0\u7684Xcode\u7684\u7248\u672c\u800c\u4e0d\u540c\u7684\u3002\u4ee5\u4e0b\u65b9\u6cd5\u9002\u7528\u4e8eXcode\u76846\u548c7\uff0c\u5355\u51fb\u5de6\u4e0a\u89d2\u7684Edit Scheme\uff0c\u5e76\u9009\u4e2dEdit Scheme\u3002<\/p> \n

\u5728\u5de6\u4fa7\u9009\u4e2dRun \uff0c\u5728\u4e0a\u65b9\u6253\u5f00 Diagnostics\u9009\u9879\u3002\u8981\u542f\u7528\u50f5\u5c38\u5bf9\u8c61\uff0c\u52fe\u9009 Enable Zombie Objects\u9009\u6846\u3002<\/p> \n

\"figure-edit-scheme.jpg\"<\/p> \n

\u5982\u679c\u4f60\u73b0\u5728\u9047\u5230EXC_BAD_ACCESS \uff0c\u5728Xcode\u7684\u63a7\u5236\u53f0\u8f93\u51fa\uff0c\u544a\u8bc9\u4f60\u8be5\u4ece\u54ea\u91cc\u67e5\u627e\u95ee\u9898\u3002\u770b\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\u8f93\u51fa\u3002 <\/p> \n

\n
-[ChildViewController respondsToSelector:] message sent to deallocated instance 0x17579780<\/pre> \n <\/div> \n 

 <\/code><\/p> \n

\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c Xcode\u544a\u8bc9\u6211\u4eec\uff0c respondsToSelector\u7684\u6d88\u606f\uff1a\u88ab\u53d1\u9001\u5230\u4e00\u4e2a\u50f5\u5c38\u5bf9\u8c61\u3002\u7136\u800c\uff0c\u50f5\u5c38\u5bf9\u8c61\u4e0d\u518d\u662fChildViewController\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b\u3002\u4ee5\u524d\u5206\u914d\u7ed9ChildViewController\u5b9e\u4f8b\u7684\u5185\u5b58\u533a\u57df\u4e0d\u518d\u6620\u5c04\u5230\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u4e3a\u4f60\u4e86\u89e3\u95ee\u9898\u4ea7\u751f\u7684\u6839\u672c\u539f\u56e0\u63d0\u4f9b\u4e00\u4e2a\u4e0d\u9519\u7684\u5efa\u8bae\u3002<\/p> \n

\u4e0d\u5e78\u7684\u662f\uff0c\u50f5\u5c38\u5bf9\u8c61\u5c06\u65e0\u6cd5\u4fdd\u5b58\u60a8\u7684\u4e00\u5929\u6bcf\u6b21\u5d29\u6e83\u7684EXC_BAD_ACCESS\u7684\u8bb0\u5f55\u3002\u65e2\u7136\u50f5\u5c38\u5bf9\u8c61\u6ca1\u6709\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u91c7\u53d6\u5176\u4ed6\u7684\u65b9\u6cd5\u8fdb\u884c\u4e00\u4e9b\u9002\u5f53\u7684\u5206\u6790\u3002<\/p> \n

6.\u5206\u6790<\/p> \n

\u5982\u679c\u50f5\u5c38\u5bf9\u8c61\u4e0d\u80fd\u89e3\u51b3\u4f60\u7684\u95ee\u9898\uff0c\u90a3\u4e48\u95ee\u9898\u7684\u6839\u6e90\u53ef\u80fd\u5c31\u4e0d\u90a3\u4e48\u7b80\u5355\u4e86\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u60a8\u9700\u8981\u4ed4\u7ec6\u770b\u770b\u5728\u5e94\u7528\u7a0b\u5e8f\u5d29\u6e83\u65f6\u6267\u884c\u7684\u4ee3\u7801\u3002\u8fd9\u53ef\u80fd\u662f\u7e41\u7410\u548c\u8017\u65f6\u7684\u3002<\/p> \n

\u4e3a\u4e86\u5e2e\u52a9\u4f60\u53d1\u73b0\u4f60\u7684\u4ee3\u7801\u7684\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528Xcode\u6765\u5206\u6790\u4f60\u7684\u4ee3\u7801\uff0c\u5e2e\u52a9\u4f60\u627e\u5230\u51fa\u73b0\u95ee\u9898\u7684\u5730\u65b9\u3002\u6ce8\u610f\uff0cXcode\u5206\u6790\u9879\u76ee\uff0c\u5b83\u4f1a\u6307\u51fa\u6bcf\u4e00\u4e2a\u6f5c\u5728\u7684\u53ef\u80fd\u51fa\u73b0\u7684\u95ee\u9898\u7684\u5730\u65b9\u3002<\/p> \n

\u4f7f\u7528Xcode\u6765\u5206\u6790\u4f60\u7684\u9879\u76ee\uff0c\u4eceXcode\u7684 Product\u83dc\u5355\u9009\u62e9 Analyze\u6216\u6309 Shift-Command-B.Xcode\u7684\u5c06\u9700\u8981\u7247\u523b\u7684\u65f6\u95f4\uff0c\u4f46\u662f\u5f53\u5b83\u5b8c\u6210\u7684\u65f6\u5019\u4f60\u4f1a\u5728\u5de6\u8fb9\u7684 Issue Navigator\u770b\u5230\u95ee\u9898\u5217\u8868\u3002\u7531Analyze\u53d1\u73b0\u7684\u95ee\u9898\u7528\u84dd\u8272\u9ad8\u4eae\u663e\u793a\u3002<\/p> \n

\"figure-analyze-1.jpg\"<\/p> \n

\u5f53\u4f60\u70b9\u51fb\u4e00\u4e2a\u95ee\u9898\uff0cXcode\u7684\u4f1a\u6307\u5411\u95ee\u9898\u4ee3\u7801\u5757\uff0c\u8fd9\u4e9b\u6b63\u662f\u4f60\u8981\u7684\u6ce8\u610f\u7684\u5730\u65b9\u3002\u6ce8\u610f\uff0cXcode\u4ec5\u4ec5\u662f\u5efa\u8bae\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u8fd9\u662f\u53ef\u80fd\u7684\uff0c\u95ee\u9898\u662f\u4e0d\u76f8\u5173\u7684\uff0c\u4e0d\u56fa\u5b9a\u3002<\/p> \n

\"figure-analyze-2.jpg\"<\/p> \n

\u5982\u679c\u4f60\u627e\u4e0d\u5230\u9020\u6210EXC_BAD_ACCESS\u7684\u9519\u8bef\uff0c\u90a3\u5c31\u9700\u8981\u4f60\u4ed4\u7ec6\u5ba1\u89c6Xcode\u9879\u76ee\uff0c\u5206\u6790\u5176\u4e2d\u53d1\u73b0\u7684\u6bcf\u4e00\u4e2a\u95ee\u9898\u3002<\/p> \n

 <\/p> \n

7.\u7ed3\u8bba<\/p> \n

EXC_BAD_ACCESS\u662f\u5f00\u53d1\u8005\u9762\u4e34\u7684\u4e00\u4e2a\u5171\u540c\u7684\u95ee\u9898\uff0c\u5b83\u662f\u624b\u52a8\u5185\u5b58\u7ba1\u7406\u56fa\u6709\u7684\u95ee\u9898\u3002\u867d\u7136\u63a8\u884cARC\u5185\u5b58\u7ba1\u7406\u65b9\u5f0f \uff08\u81ea\u52a8\u5f15\u7528\u8ba1\u6570\uff09\u4f7f\u5f97EXC_BAD_ACCESS\u6ca1\u90a3\u4e48\u9891\u7e41\uff0c\u4f46\u4ed6\u4eec\u5e76\u6ca1\u6709\u771f\u6b63\u7684\u6d88\u5931\u3002<\/p> \n

http:\/\/www.cocoachina.com\/articles\/15324<\/p> \n

 <\/p> \n<\/div>","orderid":"0","title":"EXC_BAD_ACCESS\u7684\u672c\u8d28\u8be6\u89e3\u4ee5\u53ca\u50f5\u5c38\u6a21\u5f0f\u8c03\u8bd5\u539f\u7406","smalltitle":"","mid":"0","fname":"iOS","special_id":"0","bak_id":"0","info":"0","hits":"14","pages":"1","comments":"0","posttime":"2019-11-15 18:40:53","list":"1573814453","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"http:\/\/api.cocoachina.com\/uploads\/20160225\/1456390128735342.jpg","ispic":"1","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"EXC_BAD_ACCESS<\/A> \u672c\u8d28<\/A> \u8be6\u89e3<\/A> \u4ee5\u53ca<\/A> \u50f5\u5c38<\/A> \u6a21\u5f0f<\/A> \u8c03\u8bd5<\/A> \u539f\u7406<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.34","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"EXC_BAD_ACCESS\u7684\u672c\u8d28\u8be6\u89e3\u4ee5\u53ca\u50f5\u5c38\u6a21\u5f0f\u8c03\u8bd5\u539f\u7406","lastview":"1575914890","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}