Improving DIP74: functions borrow by default, retain only if needed
Zach the Mystic via Digitalmars-d
digitalmars-d at puremagic.com
Fri Feb 27 13:07:27 PST 2015
On Friday, 27 February 2015 at 20:30:20 UTC, Steven Schveighoffer
wrote:
> OK, I found the offending issue. It's when you pass a
> parameter, the only reference holding onto it may be also
> passed as well. Something like:
>
> void foo(C c, C2 c2)
> {
> c2.c = null; // this destroys 'c' unless you opAddRef it
> before passing
> c.someFunc(); // crash
> }
>
> void main()
> {
> C c = new C; // ref counted class
> C2 c2 = new C2; // another ref counted class
> c2.c = c;
> foo(c, c2);
> }
>
> How does the compiler know in this case that it *does* have to
> opAddRef c before calling? Maybe your ARC expert can explain
> how that works.
Split-passing nested ref-counted classes with null loads! How
insidious!
More information about the Digitalmars-d
mailing list