> On Nov 2, 2016, at 13:36, Joe Groff via swift-users <swift-users@swift.org> > wrote: > >> >> On Nov 2, 2016, at 1:16 PM, Bernardo Breder via swift-users >> <swift-users@swift.org <mailto:swift-users@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
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users