MuddySky

Vizrt,Ventuz,互动触摸 Follow me @ http://weibo.com/davidhao QQ:1903443608 扫描左侧头像加微信...

IOS开发-NSString 导致程序exec_bad_access可能的原因

我的问题是给sceneid分配了一个autorelease object,其是只要加上retain那句话就不会被NSAutoreleasePool释放了,debug时sceneid也会显示summary unavailable,OK了。

具体可以参考stackoverflow的原帖NSString makes my app crash… maybe,话说我是准备提问时,在建议的相似的问题里找到的,很好用的功能,呵呵。

- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
	
    
    NSString *aStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];  
    NSLog(@"Hava received datas is :%@",[aStr substringToIndex:1]);  
    NSString *fisrtChar=[aStr substringToIndex:1];
    if([fisrtChar isEqualToString:@"1"])
    {
        NSLog(@"Get Scene id %@",[aStr substringFromIndex:2]);
        //获取
        SceneId= [[NSString alloc] init];
        SceneId=[aStr substringFromIndex:2];
        //移除最后的终止符
        SceneId=[SceneId substringToIndex:[SceneId length]-1];
        [SceneId retain];
        NSString *cmds=[NSString stringWithFormat:@"2 %@*CAMERA1*DATA GET",SceneId];
        NSLog(@"cmd we use is %@",cmds);
        [self SendCommand:cmds ReturnValueType:1];
    }
    else if([fisrtChar isEqualToString:@"2"])
    {
        NSString *cmds=[NSString stringWithFormat:@"2 %@*CAMERA1*DATA GET",SceneId];
        NSLog(@"cmd we use is %@",cmds);
        
        NSLog(@"Get camera data %@",[aStr substringFromIndex:2]);
        NSString *temp=[aStr substringFromIndex:2];
        temp=[temp substringToIndex:[temp length]-1];
      
       [cameraData removeAllObjects];
        cameraData=[[NSMutableArray alloc] init];
        //cameraData= [NSMutableArray arrayWithObjects: @"one", @"two", @"three", @"four", nil];
        
        [cameraData addObjectsFromArray:[temp componentsSeparatedByString:@" "]];
       // NSLog(@"array length %@",cameraData);
        for(int i= 0; i< [cameraData count]; i++){
           NSLog(@"aaa %@" ,[cameraData objectAtIndex:i]);
        }
        //[temp release];
        
    }
    self.tb_result.text = aStr;  
    [aStr release];  
    [client readDataWithTimeout:-1 tag:0];  
   

}


阅读更多
版权声明: https://blog.csdn.net/hjm2046/article/details/7405690
文章标签: ios开发 nsstring
个人分类: iOS
上一篇perceptivepixel PPI 55&quot;触摸屏初步测试结果
下一篇Viz Artist中关键帧的Viz CMDS使用示例
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭