关闭

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

标签: ios开发nsstring
1436人阅读 评论(0) 收藏 举报
分类:

我的问题是给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];  
   

}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:90744次
    • 积分:1353
    • 等级:
    • 排名:千里之外
    • 原创:48篇
    • 转载:0篇
    • 译文:1篇
    • 评论:33条
    最新评论