EnhancedAutoReleasePool is μ-Library for autoreleasepool.
This library is useful for :
do〜try〜catch
- Returning value from autoreleasepool().
public func autoreleasepool(@noescape code: () throws -> ()) rethrows
public func autoreleasepool<V>(@noescape code: () throws -> V?) rethrows -> V?
public func autoreleasepool<V>(@noescape code: () throws -> V) rethrows -> V
// MARK: normal autoreleasepool
(0..<10000).forEach { _ in
autoreleasepool {
let imgView = UIImageView(frame: CGRectMake(0, 0, 5000, 5000))
imgView.image = mockImage()
imgView.image = nil
}
}
XCTAssertEqual(arr1.count, 10000)
// MARK: autorelease and return value
var arr2 = [Int]()
(0..<10000).forEach { _ in
let value = autoreleasepool { () -> Int in
let imgView = UIImageView(frame: CGRectMake(0, 0, 5000, 5000))
imgView.image = mockImage()
imgView.image = nil
return 1
}
arr2.append(value)
}
print(arr2.count)
// MARK: autorelease and return value?
var arr3 = [Int?]()
(0..<10000).forEach { index in
let value = autoreleasepool { () -> Int? in
let imgView = UIImageView(frame: CGRectMake(0, 0, 5000, 5000))
imgView.image = mockImage()
imgView.image = nil
return (index % 2 == 0 ? nil : 1)
}
arr3.append(value)
}
print(arr3.count)
// MARK: autorelease with try
var arr4 = [Int]()
do {
try (0..<10000).forEach { index in
try autoreleasepool {
if (index == 5000) {
throw NSError(domain: "", code: 0, userInfo: nil)
}
let imgView = UIImageView(frame: CGRectMake(0, 0, 5000, 5000))
imgView.image = mockImage()
arr4.append(1)
imgView.image = nil
}
}
} catch ( _) {
}
print(arr4.count)
- iOS 8.0+
- Xcode 7.0+(Swift 2+)
- Add the following to your Cartfile:
github 'sgr-ksmt/EnhancedAutoReleasePool'
- Run
carthage update
- Add the framework as described.
Details: Carthage Readme
EnhancedAutoReleasePool is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'EnhancedAutoReleasePool'
and run pod install
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.:muscle:
EnhancedAutoReleasePool is under MIT license. See the LICENSE file for more info.