STL - 在 Objective-C++ 中存储 Obj-C 对象时,STL 容器是否支持 ARC?

标签 stl automatic-ref-counting objective-c++

例如,这会泄漏吗?

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/

相关文章:

objective-c - 在仅单例类的非初始化方法名称中使用 'init' 的 ARC 含义是什么

objective-c - 不可能在钥匙串(keychain)中存储电子邮件 (KeychainItemWrapper)

ios - 编辑 HSL 转换失败的 RGB 色彩空间图像

iphone - 比较两个 Xcode build设置

C++ std::equal —— 不测试大小相等的 2 个范围的理由是什么?

c++ - 在 STL 中使用引用计数的数据结构有哪些行为异常?

c++ - 插入指向 vector 的指针时出错

ios - 迭代弱引用数组,其中对象符合 Swift 中的协议(protocol)

objective-c - 如何使用 ARC 删除 Objective C 中的 C++ 指针

c++ - 在C++ 20中按长度排序std::vector <std::string>的代码是否正确?