iOSã¢ããªéçºãããã°å ¥éè ã«ããã¾ã¨ãï¼Xcode 3.2.5ã®å ´åï¼
ç°å¢å¤æ°
Javaè³ã«ã¯ã¸ã¼ã¶ã¹ããªããããObjective-cã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ã¯ä¸è¦ªåã§ãä½ããããã«ã¹ãã¨è½ã¡ããã¨ãªã©ããããããEXC_BAD_ACCESSããã§ã¦ãããªãã¾ã ã¾ããªã»ãã§ããããããã¡ãã£ã¨è¦ªåã«ããããã«ãç°å¢å¤æ°ã追å ããã
(1)TestDebugããã¸ã§ã¯ãã®å ´åããå®è¡å¯è½ãã¡ã¤ã«ãã®ä¸ã®ãTestDebugããããã«ã¯ãªãã¯
(2)ãå¼æ°ããã¯ãªãã¯
(3)ãç°å¢ã«è¨å®ãããå¤æ°ãã«ã以ä¸ã追å ãããå¤ã¯ãã¹ã¦ãYESã
- NSZombieEnabled
- NSDeallocateZombies
- MallocScribble
- MallocGuardEdges
ããã§ã¡ãã³ã¼ã¼ã¼ã£ã¨ã親åã«ãªãã
ãã°
NSLogã¨ããã®ãããã®ã ãã©ãããããã®ã¾ã¾ä½¿ã£ã¦ããã¨ãããªã«ä¾¿å©ãããªããããªãªã¼ã¹ç¨ã«å ¨é¨æ¶å»ããã¨ã大å¤ãªã®ã§ãéçºã®éã ãããããã«ãã°ãåºããããã«ããããã¤ãã£ããNSLogãæ¸ãã¦ãã¦ãããªãªã¼ã¹ç¨ã«ã¯ãªããã®ã«ãã¦ãã¾ãã
Debugã®ããã¸ã§ã¯ãã®è¨å®ãç·¨éãã
ããã¸ã§ã¯ãï¼ï¼ããã¸ã§ã¯ãè¨å®ãç·¨éãã§ãããã«ããã§ãæ§æãDebugããé¸ã³ããããªããã»ããµãã¯ããã«ãDEBUGãã追å ããããã©ã¹ãã¯ãªãã¯ãã¦ãDEBUGãã¨ã¿ã¤ãããã°è¯ããcocos2dã®ãã³ãã¬ããããã¸ã§ã¯ããä½ã£ãå ´åã¯ããããªããã»ããµãã¯ããã横æåã§ã¡ãã£ã¨éãå ´åãããããããã£ã½ãåèªãæ¢ãã
ããã¸ã§ã¯ãå_prefix.pchã«è¿½å ãã
ãã®ãã¡ã¤ã«ã¯Other Sourcesã®ä¸ã«ããã
#if DEBUG # define MyLog(fmt, ...) NSLog((@"%s[%d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); #else # define MyLog(...) # define NSLog( args... ) #endif
MyLog ã¯NSLog以ä¸ã ããã¿ãããªããã__PRETTY_FUNCTION__ã¯é¢æ°ãã¡ã½ããåãã§ã¦ããã__LINE__ã¯è¡æ°ã
ã¾ããå
¨ä½ã¯ifæãªã®ã§ããDEBUGãã®æã¯ãMyLog(å¼æ°)ãããNSLogã«å¼æ°ããã»ã«ããã足ãããã®ã«ãªã£ã¦ãDEBUGã§ãªãã¨ãã¯ãMyLog ã NSLog ãä½ã«ããªããªãã®ã§ãä½ãåºãªãã¨ãããã¨ã«ãªãã
ãããã¯ãcè¨èª ããªããã»ããµãããã¼ã¯ã¼ãã«ãcè¨èªãåå¼·ãå¿ è¦ããããããã«ããã«ããã
使ç¨ä¾
- (void)hoge { NSLog(@"IN"); MyLog(@"IN"); }
MyLogã£ã¦ã¯ã©ã¹ã§ããªãã®ã«ããããªãæ¸ããããã£ããï¼
cç¥ãããªJavaè³ã«ã¯è¡æã§ã¤ãã
å®è¡ããã¨ã³ã³ã½ã¼ã«ã«ä»¥ä¸
2011-01-21 14:45:35.149 TestDebug[91125:207] IN 2011-01-21 14:45:35.151 TestDebug[91125:207] -[TestDebugViewController hoge][29] IN
ï¼è¡ç®ã¯NSLogã§åºããå ´åãèªåã§æ¸¡ããæååãINãããã§ã¦ãªãã
ï¼è¡ç®ã¯MyLogã§åºããå ´åãèªåã§æ¸¡ããæååãINãã®åã«ãã¯ã©ã¹åã«ã¡ã½ããåãè¡æ°ãã§ã¦ãã¦ã¨ã¦ã¼ã便å©ï¼
ãã°ã®åºãæ¹
å
¥éè
ã¯ãã£ã±ããã°ã£ãããã°ã
ãã¼ãããããã¼ãã¨ããå ´åã¯ãã¡ã½ããã®å
¥ãå£ã«ã¿ããªãINãã¨ãæ¸ãããwãæ°ã«ãªãå¤æ°ã®ä¸èº«ã¯çã£ç«¯ããæ¸ãåºããããããããJavaã®äººã«ã¨ã£ã¦é¢åããããããããªããã¨ã®ä¸ã¤ãããã©ã¼ããããããã£ã¦ãããã¨ã
æ°å¤ã¨ã
int num = 0; ã»ã»ã» DLog(@"æ° num = %d",num);
æå㯠%@ã
ãNSLogããã©ã¼ããããã§ãããã¨è²ã
ã§ã¦ãããAppleã®ããã¥ã¡ã³ãããã¡ãããããããã
Javaè³ã 㨠"æ° num="+num ã ãã ãã©ã¹è¨å·ã§æåå足ãç®ãã¦ãã¾ããããããã
ãããã°ã®å®è¡
ãã½ã¼ã¹ãã¡ã¤ã«ã®è¡æ°ãã¯ãªãã¯ããã¨ãéãå°ãã¤ããå°ãã¤ãã¦ããã¨ããããã°ãã§ãããéãå°ã¯ãã©ãã°ï¼ããããã§é²ã«ãªã£ã¦æ¶ãããï¼ãããæåããããªãã£ããªãï¼
Leaksã®ä½¿ãæ¹ãã©ã
å®è¡ï¼ï¼ããã©ã¼ãã³ã¹ãã¼ã«ã使ã£ã¦å®è¡ï¼ï¼Leaksãã§èµ·åããã
Instrumentsãèµ·åããã¨ãAllocatonã¨Leaksã®ï¼ã¤ã»ããã§ã§ã¦ããã®ã§ãLeaksãã¯ãªãã¯ããã¨ãLeaksã®è¡¨ç¤ºã«ãªãã
ãã©ã¹ãã¼ã¯ãã¯ãªãã¯ããã¨ãããªã«ãã¦ã³ã該å½ç®æã®ã½ã¼ã¹ãã§ã¦ããã
iãã¼ã¯ãããã¨ããããã¢ãããã§ã¦ãã©ãããã¡ã½ããããã©ã£ã¦å¼ã°ãããããããã
ã¾ã¨ã
cè¨èªç¥ã£ã¦ãªãã¨ãã£ã±ããããããT_Tã¨ããããã
ã¾ãXcodeã¯ãã¼ã¸ã§ã³ãå¤ããã¨æä½ãããã«å¾®å¦ã«å¤ãã£ããããã®ã§ãããæ¹ã¨èãæ¹ã¯åãé¢ãã¦è¦ãã¦ããã®ãè¯ãããç°å¢å¤æ°ã«ä½ã追å ããã¨ã¨ã©ã¼ã詳細ã«ã§ã¦ãããããããªããã»ããµã¨ãããªããã»ããµãã¯ãã¨ãããªãããããããããã¨ãããã¨ã¯ãcè¨èªãªã©ããã¤ãªããç¥èãããããXcodeã§ã¯å®éã©ãã§ã©ãããã®ãã¯ãXcodeã®æä½ã®ä»æ¹ã®è©±ã
å®æ©ã§ã®ãã¹ãã¯å¿ é ã
Javaè³ã®äººã®ããã®ã¡ã¢ãªãªã¼ã¯å¯¾çæé
- allocãã¦initãããã©ã£ãã§ãªãªã¼ã¹ããªãã¨ãããªãã¨ãã大ååãè¤éãªãã¨ããã¦ããªããã°ãã¡ã¢ãªãªã¼ã¯ã¯ãªãªã¼ã¹ãã¦ããªãå ´åãã»ã¨ãã©ãallocã¨initã§ããã»ã¨ãã©autoreleaseã¤ãã¨ãã¦ãããããã ãã ã¨ããå ´åã¯ã¤ããªãã
- 使ãã¯ã©ã¹ã®åæåã¡ã½ããã«ãã£ã¦ã¯ãautoreleaseãããã®ãããã®ã§ããã¯ç¢ºèª
- cocos2dã®åºæ¬ã®åæåã¯ãnodeãå¿ãããªããã