简体   繁体   English

不释放NSMutableString

[英]Not release NSMutableString

I started developing a project in ios-5, I have created database in my application. 我开始在ios-5中开发一个项目,我在我的应用程序中创建了数据库。 Here I create bdgDBArr in appDelegate that contains values like 93,55,68,95,45... I want to create string like badge_id= @"93,55,68,95,45" here appDelegate.sb is NSString type and sb1 is NSMutableString type 在这里,我在appDelegate中创建了包含93,55,68,95,45之类的值的bdgDBArr ...我想创建像badge_id = @“93,55,68,95,45”这样的字符串,这里appDelegate.sb是NSString类型, sb1是NSMutableString类型

This is my code 这是我的代码

NSMutableString *sb1 = [[NSMutableString alloc] init];

if (![appDelegate.bdgDBArr count]==0) {
    for (int i=0; i < [appDelegate.bdgDBArr count]; i++)  { 
        if (!i==0) {
             [sb1 appendString:@","];
        }
        [sb1 appendString:[[appDelegate.bdgDBArr objectAtIndex:i] valueForKey:@"key1"]];
    }
}
else {
    [sb1 appendString:@""];
}

appDelegate.sb = sb1;
NSLog(@"appDelegate.sb  showSB===%@",appDelegate.sb);
[sb1 release];  //error wait_fences: failed to receive reply: 10004003
sb1 = nil;

This code is working perfectly and get the output 93,55,68,45 but at the same time I got this error in NSLog 这段代码工作正常并得到输出93,55,68,45,但同时我在NSLog中得到了这个错误

wait_fences: failed to receive reply: 10004003

Any ideas? 有任何想法吗?

I can't help with your problem but you can — and should — reduce your code down to a one-liner: appDelegate.sb = [appDelegate.bdgDBArr componentsJoinedByString:@","]; 我无法解决您的问题,但您可以 - 而且应该 - 将您的代码减少到一行: appDelegate.sb = [appDelegate.bdgDBArr componentsJoinedByString:@","]; which is much more expressive and does the right thing. 这是更具表现力和正确的事情。

And while we're there: 而我们在那里:
Objective-C makes it rather easy to write code that can be read like prose. Objective-C使得编写可以像散文一样阅读的代码变得相当容易。 Don't break that by using member/variable names like sb or bdgDBArr . 不要使用sbbdgDBArr等成员/变量名来破坏它。

Oh and there is an operator to test for inequality: != use that instead of negating the result of an equality test. 哦,有一个运算符来测试不等式: !=使用它而不是否定相等测试的结果。 Your future self and every other person looking at your code will be thankful. 你未来的自我和每一个看你代码的人都会感激不尽。

just to try: use autorelease instead of release. 只是为了尝试:使用autorelease而不是release。 does it change something? 它改变了什么吗?

is your property appDelegate.sb used in app delegate with a @syntetise setter/getter, or did you used your own code for the setter? 是您的属性appDelegate.sb在app委托中使用@syntetise setter / getter,或者您是否使用自己的代码作为setter? in this case post your code, please. 在这种情况下,请发布您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM