Reputation: 578
Simple question:
I have an AVPlayer property called player (could be any strong property, its just AVPlayer for example's sake).
If it has already been allocated (and is not nil) and I re-allocate it without setting it to nil:
self.player = [[AVDelegatingPlayer alloc] initWithURL:[NSURL URLWithString:urlString]];
Are there memory implications for this in an ARC environment?
Upvotes: 0
Views: 32
Reputation: 13999
Take a look at clang source code for storing an object into a __strong variable.
https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGObjC.cpp#L2108-L2119
// Retain the new value.
newValue = EmitARCRetain(type, newValue);
// Read the old value.
llvm::Value *oldValue = EmitLoadOfScalar(dst, SourceLocation());
// Store. We do this before the release so that any deallocs won't
// see the old value.
EmitStoreOfScalar(newValue, dst);
// Finally, release the old value.
EmitARCRelease(oldValue, dst.isARCPreciseLifetime());
So your code would be compiled as the following.
id newValue = [[AVDelegatingPlayer alloc] initWithURL:[NSURL URLWithString:urlString]];
id oldValue = self.player;
self.player = newValue;
[oldValue release];
Upvotes: 1