posts - 9,  comments - 0,  trackbacks - 0
1.Add a new "revision.h"file
2.Add a new Run script for the target 
3.
 input the REV=`svnversion -nc | /usr/bin/sed -'s/^[^:]*://;s/[A-Za-z]//'`
BASEVERNUM=`/usr/libexec/PlistBuddy -"Print :CFBundleShortVersionString" "${INFOPLIST_FILE}"`
/usr/libexec/PlistBuddy -"Set :CFBundleVersion $BASEVERNUM.$REV" "${INFOPLIST_FILE}"

4.clean the target and run
posted @ 2011-08-15 12:11 雨 阅读(269) | 评论 (0)编辑 收藏
http://developer.apple.com/library/ios/#qa/qa1686/_index.html
posted @ 2011-06-14 10:12 雨 阅读(135) | 评论 (0)编辑 收藏

1: 为工程运行时加入 NSZombieEnabled 环境变量,并设为启用,则在 EXC_BAD_ACCESS 发生时,XCode 的 Console 会打印出问题描述。

首先双击 XCode 工程中,Executables 下的 可执行模组,


在弹出窗口中,Variables to be set in the environment,添加 NSZombieEnabled,并设定为 YES,点击选中复选框启用此变量。

这样,运行 Objective-C 时会看到控制台输出错误信息

这条消息对于定位问题有很好的提示作用。但是很多时候,只有这条提示是不够的,我们需要更多的提示来帮助定位问题,这时候再加入 MallocStackLogging 来启用malloc记录。

当错误发生后,在终端执行:

malloc_history ${App_PID} ${Object_instance_addr}

    则会获得相应的 malloc 历史记录,比如对于上一个控制台输出

Untitled[3646:a0f] *** -[CFString release]: message sent to deallocated instance 0x10010d340

    则我们可以在终端执行,结果如下:

Buick-Wongs-MacBook-Pro:Downloads buick$ malloc_history 3646 0x10010d340
malloc_history Report Version: 2.0
Process: Untitled [3646]
Path: /Users/buick/Desktop/Untitled/build/Debug/Untitled
Load Address: 0×100000000
Identifier: Untitled
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: gdb-i386-apple-darwin [3638]

Date/Time: 2011-02-01 15:07:04.181 +0800
OS Version: Mac OS X 10.6.6 (10J567)
Report Version: 6

ALLOC 0x10010d340-0x10010d357 [size=24]: thread_7fff70118ca0 |start | main | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | +[NSString initialize] | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | NXCreateMapTableFromZone | malloc_zone_malloc
—-
FREE 0x10010d340-0x10010d357 [size=24]: thread_7fff70118ca0 |start | main | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | _finishInitializing | free

ALLOC 0x10010d340-0x10010d357 [size=24]: thread_7fff70118ca0 |start | main | -[NSPlaceholderString initWithString:] | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | _class_initialize | +[NSMutableString initialize] | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | NXCreateMapTableFromZone | malloc_zone_malloc
—-
FREE 0x10010d340-0x10010d357 [size=24]: thread_7fff70118ca0 |start | main | -[NSPlaceholderString initWithString:] | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | _class_initialize | _finishInitializing | free

ALLOC 0x10010d340-0x10010d35f [size=32]: thread_7fff70118ca0 |start | main | -[NSCFString substringWithRange:] | CFStringCreateWithSubstring | __CFStringCreateImmutableFunnel3 | _CFRuntimeCreateInstance | malloc_zone_malloc

    这样就可以很快的定位出问题的代码片段了,注意输出的最后一行,,,这行虽然不是问题的最终原因,但是离问题点已经很近了,随着它找下去,八成就会找到问题。

posted @ 2011-02-21 09:51 雨 阅读(362) | 评论 (0)编辑 收藏
 1 NSMutableString*tempString=[[NSMutableString alloc]initWithFormat:@"%@",@"testmemory"];
 2     NSLog(@"tempString retainCount-----%D",[tempString retainCount]);
 3     NSLog(@"tempString -----%p---%p",tempString,&tempString);
 4     
 5     NSMutableString*string1=[tempString retain];
 6     NSLog(@"string1 retainCount-----%D",[string1 retainCount]);
 7     NSLog(@"string1 -----%p---%p",string1,&string1);
 8     
 9     NSMutableString*string2=[tempString mutableCopy];
10     NSLog(@"string2 retainCount-----%D",[string2 retainCount]);
11     NSLog(@"string2 -----%p---%p",string2,&string2);
12     
13     
14     NSString*s=[[NSString alloc]initWithFormat:@"%@",@"hello"];
15     NSLog(@"s retainCount-----%D",[s retainCount]);
16     NSLog(@"s -----%p---%p",s,&s);
17     NSString*st=[s copy];
18     NSLog(@"st retainCount-----%D",[st retainCount]);
19     NSLog(@"st -----%p---%p",st,&st);
20     NSString*str=[s retain];
21     NSLog(@"str retainCount-----%D",[str retainCount]);
22     NSLog(@"str -----%p---%p",str,&str);

retain 时是表示指向了同一个内存空间,只是内存空间的retainCount加了1,其他的都没变,但是当copy时,如果那个内存单元里面的值是不可变的时候,我们跟retain是一样的,只是内存空间的retainCount加了1!如果那个内存单元里面的值是可变的时候,其实在在内存中另外给分配了一块内存空间,然后把值赋给内存空间里面。原来那个内存空间的retainCount不加1,现在新分配的内存空间retainCount1.

posted @ 2010-12-11 15:24 雨 阅读(349) | 评论 (0)编辑 收藏
程序发布的时候会因为一些nslog影响速度,所以在程序release的时候尽量把nslog去除掉。
在程序中加入以下代码即可

#ifndef __OPTIMIZE__

#    define NSLog(...) NSLog(__VA_ARGS__)

#else

#    define NSLog(...) {}

#endif

posted @ 2010-12-08 15:12 雨 阅读(223) | 评论 (0)编辑 收藏
<2010年12月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(1)

随笔档案

文章分类

搜索

  •  

最新评论

阅读排行榜

评论排行榜