On Thu, 17 Apr 2014 18:52:10 -0400, Walter Bright
<[email protected]> wrote:
On 4/17/2014 3:18 PM, Steven Schveighoffer wrote:
During the entire processing, you never increment/decrement a reference
count,
because the caller will have passed data to you with an incremented
count.
Just because ARC protects the data, doesn't mean you need to constantly
and
needlessly increment/decrement references. If you know the data won't
go away
while you are using it, you can just ignore the reference counting
aspect.
The salient point there is "if you know". If you are doing it, it is not
guaranteed memory safe by the compiler. If the compiler is doing it, how
does it know?
When I said you, I misspoke. I meant the compiler. If it isn't sure, it
increments the count. But any objects passed into a function are already
incremented. Basically it's like a mutex lock. You only need to increment
at the most outer level of where you are using it.
This idea that every time you pass around a variable you need to adjust
counts is just not true. This is not shared_ptr.
You really are doing *manual*, not automatic, ARC here, because you are
making decisions about when ARC can be skipped, and you must make those
decisions in order to have it run at a reasonable speed.
Absolutely not, the compiler knows whether the count needs to be
incremented, I don't need to know. In fact, in ARC, you are NOT ALLOWED to
increment or decrement the count manually.
-Steve