[swift-users] Autoreleasepool for Ubuntu
Jordan Rose
jordan_rose at apple.com
Wed Nov 2 15:41:10 CDT 2016
> On Nov 2, 2016, at 13:36, Joe Groff via swift-users <swift-users at swift.org> wrote:
>
>>
>> On Nov 2, 2016, at 1:16 PM, Bernardo Breder via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>>
>> In my http server i want to manager the memory all the time that we close a socket, like the example of manager in this link: http://stackoverflow.com/questions/25860942/is-it-necessary-to-use-autoreleasepool-in-a-swift-program <http://stackoverflow.com/questions/25860942/is-it-necessary-to-use-autoreleasepool-in-a-swift-program>
>>
>> Algorithm that show the ideia:
>>
>> func request(content) { ... }
>>
>> let server = myserver()
>> while let client = server.accept() {
>> autoreleasepool {
>> client.send(request(client.read()))
>> client.close()
>> }
>> }
>
> Is `client` really getting autoreleased somewhere? autoreleasepool shouldn't normally be necessary. The client will be released when you go out of scope.
The problem is that on Apple platforms, the Foundation APIs used to implement the client autorelease things all over the place, so you need an autorelease pool somewhere to clean up the mess intermediate objects returned at +0.
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161102/b2af32c6/attachment.html>
More information about the swift-users
mailing list