WeakReference implementation in .NET has an IsAlive Property.
1) Are there any performance/behavior differences between using the IsAlive
property or testing whether the Target
property is not null?
2) IsAlive
is a redundant property?
Thanks.
WeakReference implementation in .NET has an IsAlive Property.
1) Are there any performance/behavior differences between using the IsAlive
property or testing whether the Target
property is not null?
2) IsAlive
is a redundant property?
Thanks.
1) No. Internally, IsAlive is doing almost exactly the same logic as checking target, and seeing if it's null.
2) Somewhat, since checking whether ref.Target != null
is pretty much equivelent to ref.IsAlive
. However, IsAlive
is more expressive, and potentially easier to understand when maintaining the code.
Looking at the source code, there is no difference in behavior between them. obj.IsAlive
is simply more convenient and readable then obj.Target != null
.