discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Interesting difference in memory management of MacOS Foundation and GNUs


From: Mathias Bauer
Subject: Interesting difference in memory management of MacOS Foundation and GNUstep
Date: Fri, 14 Feb 2014 10:53:27 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

Hi dear list members,

I have ported most parts of the CocoaHTTPServer from Robbie Hanson including GCDAsyncSocket to Linux and found an interesting difference in memory management.

Here's the dealloc function of GCDAsyncSocket:

- (void)dealloc
{
        LogInfo(@"%@ - %@ (start)", THIS_METHOD, self);
        
        if (dispatch_get_specific(IsOnSocketQueueOrTargetQueueKey))
        {
                [self closeWithError:nil];
        }
        else
        {
                dispatch_sync(socketQueue, ^{
                        [self closeWithError:nil];
                });
        }

This method crashes on Linux when the dealloc function in not called in the socket or target queue as the block that calls closeWithError is executed in this case. Catching "self" in it increments and after block execution decrements the retain count of "self". Doing this in a dealloc method of course leads into disaster.

But the same code does not crash on MacOS or iOS, even if the block containing closwWithError is executed.

I don't understand that, but maybe somebody knowing the differences better than I can explain that.

Best regards,
Mathias



reply via email to

[Prev in Thread] Current Thread [Next in Thread]