libolf 2019-12-18 16:55 采纳率: 66.7%
浏览 90

新手求问这段代码有内存泄漏吗?

- (NSString *) getRandomWord:(int)count{
    int nextNum = -1;
    NSStringEncoding gbkEncoding =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    NSString *result = [[NSString alloc] init];

    for (int i = 0; i < count; i++) {
        @autoreleasepool {
            //  [0, 100)之间的随机数
            nextNum = arc4random() % 100;
            if (nextNum % 4 == 0) {
                int heightPos = 176 + arc4random() % 39;
                int lowPos = 161 + arc4random() % 93;
                Byte wordBytes[2] = {(Byte)heightPos, (Byte)lowPos};
                NSString *oneWord = [[NSString alloc] initWithBytes:wordBytes length:2 encoding:gbkEncoding];
                result = [result stringByAppendingString:oneWord];
            }else if (nextNum % 4 == 1){
                char c = 65 + arc4random() % 26;
                result = [result stringByAppendingFormat:@"%c", c];
            }else if (nextNum % 4 == 2){
                char c = 97 + arc4random() % 26;
                result = [result stringByAppendingFormat:@"%c", c];
            }else{
                int num = 1 + arc4random() % 10;
                result = [result stringByAppendingFormat:@"%d", num];
            }
        }
    }

    return result;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧