iOS功能泄露内存

时间:2014-10-24 01:47:21

标签: ios objective-c memory-leaks posix

我正在使用POSIX套接字创建客户端套接字。由于此过程需要NSArray来使用数据,因此我编写了以下两个循环来将unsigned char数组转换为NSArray,反之亦然。我查看了内存情况,发现多次运行这些函数时内存使用量增加缓慢。任何人都可以发现任何潜在的内存泄漏吗?

//read code run in background
NSMutableArray * arr = [[NSMutableArray alloc] init];
NSUInteger i = 0;
NSNumber *aUChar = 0;
for(;;)
{
    n = read(sockfd,buffer,SOCKET_SIZE);
    if (n > 0)
    {
        [arr removeAllObjects];
        for (i = 0; i < n; i++)
        {
            aUChar = [NSNumber numberWithUnsignedChar:buffer[i]];
            [arr addObject:aUChar];
        }
        //do sth with arr 
    }
}

//write code run in main thread when function called
int n=0;
unsigned char buffer[SOCKET_SIZE];
NSUInteger i = 0;
NSNumber *tmpnum;
NSArray *data_arr = [command.arguments objectAtIndex : 0];
for (i = 0; i < SOCKET_SIZE; i++)
{
    tmpnum = [data_arr objectAtIndex:i];
    buffer[i] = [tmpnum charValue];
}
n = write(sockfd,buffer,TCP_SOCKET_SIZE);

0 个答案:

没有答案