为什么Instruments在以下代码中显示如此多的泄漏?

Raj*_*ana 0 memory-leaks objective-c instruments

- (NSArray *) makeKeyValueArray: (NSArray *) arr
{
    NSMutableArray *result = [[NSMutableArray alloc] init];
    for(int i = 0; i < [arr count]; i++)
    {
        [result addObject:[[KeyValue alloc] initWithData:[arr objectAtIndex:i] :[arr objectAtIndex:i]]];
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

仪器在上面的代码中显示188个泄漏,为什么?有人可以向我解释一下吗?

Par*_*fna 5

- (NSArray *) makeKeyValueArray: (NSArray *) arr
{
    NSMutableArray *result = [[NSMutableArray alloc] init];
    for(int i = 0; i < [arr count]; i++)
    {
        id obj = [[KeyValue alloc] initWithData:[arr objectAtIndex:i] :[arr objectAtIndex:i]]; // obj reference count is now 1, you are the owner
        [result addObject:obj]; //reference count is now 2, the array is also an owner as well as you.
        [obj release];// reference count is now 1, you are not the owner anymore
    }
    return [result autorelease];
}  
Run Code Online (Sandbox Code Playgroud)

看一下基本内存管理规则

你必须放弃你拥有的物品的所有权