diff --git a/Project.toml b/Project.toml index fd853cd..4f5dadd 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ObjectiveC" uuid = "e86c9b32-1129-44ac-8ea0-90d5bb39ded9" -version = "2.0.0" +version = "2.0.1" [deps] CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" diff --git a/src/foundation.jl b/src/foundation.jl index 05002cb..4cf81cc 100644 --- a/src/foundation.jl +++ b/src/foundation.jl @@ -407,15 +407,14 @@ end export NSAutoreleasePool, @autoreleasepool, drain -@objcwrapper immutable=false NSAutoreleasePool <: NSObject +@objcwrapper NSAutoreleasePool <: NSObject -function NSAutoreleasePool(; autorelease=true) +function NSAutoreleasePool() obj = NSAutoreleasePool(@objc [NSAutoreleasePool alloc]::id{NSAutoreleasePool}) - if autorelease - finalizer(release, obj) - end # XXX: this init call itself requires an autoreleasepool to be active... @objc [obj::id{NSAutoreleasePool} init]::id{NSAutoreleasePool} + # NOTE: we don't register a finalizer, as it's better to drain the pool, + # and it's not allowed to both drain and release. obj end @@ -432,8 +431,7 @@ function NSAutoreleasePool(f::Base.Callable) sticky = task.sticky task.sticky = true - # pools cannot be double released, so we need to disable the finalizer - pool = NSAutoreleasePool(; autorelease=false) + pool = NSAutoreleasePool() try f() finally diff --git a/test/runtests.jl b/test/runtests.jl index 164ee47..dfd5d0a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -113,7 +113,7 @@ using .Foundation @objc [obj::id{NSString} release]::id{NSString} # low-level API - let pool=NSAutoreleasePool(; autorelease=false) + let pool=NSAutoreleasePool() obj = NSString(@objc [NSString new]::id{NSString}) autorelease(obj) drain(pool)