Take the 2-minute tour ×




Type: System.Object

The object to track or null.

As far as I can understand this, it means that 'null' is a valid parameter for the WeakReference object...

The problem I see is following: when extracting value I will check if Target is not null... and if not - will use it as an object. But if "null" is passed as original target, then property "Target" of the weakReference object will not give me information: is object already garbage-collected or it was null always.

Question: if "Target" is null how can I understand that it because original object was null as well?


share|improve this question
I wouldn't expect you to be able to tell the difference between null because the target was collected vs. null because there was no target in the first place. Why do you need to tell the difference? –  Gabe Apr 30 '12 at 4:46
Because i'm thinking about storing 'null' as value, see more details here: stackoverflow.com/questions/10378161/… –  Budda Apr 30 '12 at 12:27

2 Answers 2

You might want to try the IsAlive property. It's a boolean value that will tell you if the object pointed to has been collected.

share|improve this answer
IsAlive is 'false' immediately when weak-object is created with 'null' target. –  Budda Apr 30 '12 at 12:36

It looks like special object (that means 'there are no data') should be used instead of 'null' (same/similar to answer in Can null be inserted into Cache? question)

share|improve this answer

Your Answer


