0

http://msdn.microsoft.com/en-us/library/xt0a1s34(v=vs.100).aspx

Parameters

target

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?

Thanks.

Community
  • 1
  • 1
Budda
  • 18,015
  • 33
  • 124
  • 206
  • 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 04:46
  • Because i'm thinking about storing 'null' as value, see more details here: http://stackoverflow.com/questions/10378161/can-null-be-inserted-into-cache – Budda Apr 30 '12 at 12:27

2 Answers2

0

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.

Mike
  • 1
0

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)

Community
  • 1
  • 1
Budda
  • 18,015
  • 33
  • 124
  • 206