double free *** set a breakpoint in malloc_error_break to debug的另类错误原因
来源:互联网 发布:网络女主播洗澡的视频 编辑:程序博客网 时间:2024/06/04 18:52
在项目中出现double free的错误,找了好久没看到哪一个对象调用了两次release的情况,用注释定位法,终于不再出现错误提示了,
这个错误有点隐蔽,因为在写代码时,alloc和release是成对出现的。有以下代码:
NSString *strTemp = [[NSStringalloc] initWithString:inputText];
[strTemp release];
因为strTemp里边一些标点符号要去除,中间加了下面几句
strTemp = [strTemp stringByReplacingOccurrencesOfString:@"。" withString:@""];
strTemp = [strTemp stringByReplacingOccurrencesOfString:@"," withString:@""];
strTemp = [strTemp stringByReplacingOccurrencesOfString:@" " withString:@""];
也就相当于
NSString *strTemp = [[NSString alloc] initWithString:inputText];
strTemp = [strTemp stringByReplacingOccurrencesOfString:@"。" withString:@""];
strTemp = [strTemp stringByReplacingOccurrencesOfString:@"," withString:@""];
strTemp = [strTemp stringByReplacingOccurrencesOfString:@" " withString:@""];
[strTemp release];
其中stringByReplacingOccurrencesOfString函数返回值是autorelease性质的,不用主动释放。
错误隐蔽之处是如果没有标点符号时,不会出错,也即strTemp和原来还是一个对象,但是如果inputText里有句号等标点,strTemp就指向一个AutoRelease性质的对象了。这时你调用[strTemp release];当然也就会出现double free的错误了。
- double free *** set a breakpoint in malloc_error_break to debug的另类错误原因
- double free *** set a breakpoint in malloc_error_break to debug
- set a breakpoint in malloc_error_break to debug
- set a breakpoint in malloc_error_break to debug
- eclipse进行Debug的时候,发出“java breakpoint unable to install breakpoint”错误
- eclipse进行Debug的时候,发出“java breakpoint unable to install breakpoint”错误
- IAR调试出现the stack plug-in failed to set a breakpoint on "main"
- 在IAR 中出现the stack plug-in failed to set a breakpoint on "main"
- 【解决方法】eclipse debug Unable to install breakpoint in xxx
- IAR调试cc2540 时 出现The stack plug-in failed to set a breakpoint on "main". 解决方法
- debug时报Unable to install breakpoint in XX due to missing line number attributes
- How to set a breakpoint on a property within a third-party managed component?
- [xxx objectForKey:]: unrecognized selector sent to instance 错误的另类原因
- Unable to install breakpoint in...
- Unable to install breakpoint in
- STS或者Eclipse在debug时弹框提示”Unable to install breakpoint in class...“解决之道
- Eclipse debug 断点不能调试 ,Eclipse Unable to install breakpoint in 解决办法
- STS/Eclipse debug时提示“Unable to install breakpoint in class...“
- yii中find简单用法
- 排序算法
- Fuzhou OJ Problem 1894 志愿者选拔
- INSTALL_FAILED_UPDATE_INCOMPATIBLE
- 基于HEVC的码率控制的相关提案的文献综述
- double free *** set a breakpoint in malloc_error_break to debug的另类错误原因
- 虚拟机下linux上网设置收获——亲试可行
- Extjs中Combo组件添加tooltip
- POJ1321 搜索之回溯法
- RMQ
- JDK官方网址
- golang关于json库的一个比较容易陷入的坑 uint8[]数组的json转换问题.
- Linux kernel crash analysis example
- MySQL查看和修改wait_timeout