Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do STL containers support ARC when storing Obj-C objects in Objective-C++?

For example, would this leak?

static std::tuple<CGSize, NSURL *> getThumbnailURL() {
  return std::make_tuple(CGSizeMake(100, 100), [NSURL URLWithString:@"http://examples.com/image.jpg"]);
}
like image 212
Jon Sharkey Avatar asked Jun 23 '15 18:06

Jon Sharkey


1 Answers

No, it wouldn't leak. That NSURL object would be managed by ARC properly.

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 *> is the same as std::tuple<CGSize, NSURL __strong *>. Thus NSURL object will be released when the std::tuple instance is destructed.

like image 194
Kazuki Sakamoto Avatar answered Sep 30 '22 19:09

Kazuki Sakamoto