例如,这会泄漏吗?
static std::tuple<CGSize, NSURL *> getThumbnailURL() {
return std::make_tuple(CGSizeMake(100, 100), [NSURL URLWithString:@"http://examples.com/image.jpg"]);
}
最佳答案
不,它不会泄漏。该 NSURL 对象将由 ARC 正确管理。
http://clang.llvm.org/docs/AutomaticReferenceCounting.html#template-arguments
If a template argument for a template type parameter is an retainable object owner type that does not have an explicit ownership qualifier, it is adjusted to have __strong qualification.
std::tuple<CGSize, NSURL *>
与 std::tuple<CGSize, NSURL __strong *>
相同.因此,当 std::tuple 实例被破坏时,NSURL 对象将被释放。
关于STL - 在 Objective-C++ 中存储 Obj-C 对象时,STL 容器是否支持 ARC?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31010390/