Jon*_*key 5 stl objective-c++ automatic-ref-counting
例如,会泄漏吗?
static std::tuple<CGSize, NSURL *> getThumbnailURL() {
return std::make_tuple(CGSizeMake(100, 100), [NSURL URLWithString:@"http://examples.com/image.jpg"]);
}
Run Code Online (Sandbox Code Playgroud)
不,它不会泄漏。该 NSURL 对象将由 ARC 正确管理。
http://clang.llvm.org/docs/AutomaticReferenceCounting.html#template-arguments
如果模板类型形参的模板实参是不具有显式所有权限定符的可保留对象所有者类型,则将其调整为具有 __strong 限定符。
std::tuple<CGSize, NSURL *>
是相同的std::tuple<CGSize, NSURL __strong *>
。因此,当 std::tuple 实例被破坏时,NSURL 对象将被释放。
归档时间: |
|
查看次数: |
443 次 |
最近记录: |