armadsen / ORSSerialPort

Serial port library for Objective-C and Swift macOS apps
MIT License
751 stars 183 forks source link

ORSSerialPort instances are retained by the class #140

Closed armadsen closed 5 years ago

armadsen commented 5 years ago

Despite the use of +[NSValue valueWithNonretainedObject:], ports are retained by allSerialPorts here:

+ (void)addSerialPort:(ORSSerialPort *)port;
{
    [allSerialPorts addObject:[NSValue valueWithNonretainedObject:port]];
}

+ (void)removeSerialPort:(ORSSerialPort *)port;
{
    NSValue *valueToRemove = nil;
    for (NSValue *value in allSerialPorts)
    {
        if ([value nonretainedObjectValue] == port)
        {
            valueToRemove = value;
            break;
        }
    }
    if (valueToRemove) [allSerialPorts removeObject:valueToRemove];
}

This could be fixed by using NSPointerArray instead.

I'm cautious about changing this, though, because it's likely to break code that is inadvertently relying on this behavior.

armadsen commented 5 years ago

Nevermind, this isn't actually true. It was only the retain cycles (see #139) keeping the port alive.