[swift-users] Autoreleasepool for Ubuntu

Bernardo Breder bernardobreder at gmail.com
Wed Nov 2 13:11:34 CDT 2016


I want to manager the memory, using the autoreleasepool block, with ubuntu
environment, as we can do with Xcode.

2016-11-02 15:34 GMT-02:00 Joe Groff <jgroff at apple.com>:

>
> On Nov 2, 2016, at 10:17 AM, Jordan Rose <jordan_rose at apple.com> wrote:
>
>
> On Nov 2, 2016, at 09:42, Joe Groff via swift-users <swift-users at swift.org>
> wrote:
>
>
> On Nov 1, 2016, at 6:40 PM, Bernardo Breder via swift-users <
> swift-users at swift.org> wrote:
>
> Hello,
>
> I want to create a mini http server project and execute at Ubuntu 15. The
> Xcode compile and access the function "autoreleasepool", but when i compile
> the same code at Ubuntu, this function not found
>
> For example, i can compile the code above at Xcode:
>
> while true {
>    autoreleasepool {
>    var test: Data = "HTTP/1.1 200 OK\r\nContent-Length:
> 1\r\n\r\na".data(using: .utf8)!
>    }
> }
>
> But when i try to compile at Ubuntu:
>
> git at breder:~$ cat main.swift
> import Foundation
>
> while true {
>    autoreleasepool {
>    var test: Data = "HTTP/1.1 200 OK\r\nContent-Length:
> 1\r\n\r\na".data(using: .utf8)!
>    }
> }
>
> git at breder:~$ swiftc main.swift
> main.swift:4:5: error: use of unresolved identifier 'autoreleasepool'
>    autoreleasepool {
>    ^~~~~~~~~~~~~~~
>
>
> Autoreleasepools are an ObjC compatibility feature. They aren't necessary
> in standalone Swift.
>
>
> But they *are* necessary in Swift programs on Apple platforms (that don’t
> use RunLoop, anyway). Philippe, what do you think? What’s the right way to
> write cross-platform code that doesn’t use RunLoop or dispatch_main for an
> implicit autorelease pool?
>
> (/me remembers +[NSAutoreleasePool drain] from the ObjC-GC days)
>
>
> If you must, you could conditionally define `autoreleasepool` to just call
> its argument as a compatibility shim.
>
> -Joe
>



-- 
Nome : Bernardo Breder
Product : Breder Language
Site : bernardobreder.com
Email : bernardobreder at gmail.com
Email : bbreder at tecgraf.puc-rio.br
Email : contato at bernardobreder.com
Graduação : UFF - Ciência da Computação
Mestrado : UFF - Ciência da Computação
Trabalho : TecGraf - PUC-RIO
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161102/50f9aa3f/attachment.html>


More information about the swift-users mailing list