Possible Duplicate:
When should weak references be used?
Hi,
When is it good practice to use weak references?
Could somebody provide an example?
Possible Duplicate:
When should weak references be used?
Hi,
When is it good practice to use weak references?
Could somebody provide an example?
An example where they could be used is in implementing a caching container.
CAB (and its open source equivalent, bbv.Common.EventBroker) uses weak references to allow loosely-coupled event subscriptions between forms (or their MVC controllers).
This allows, for instance, form-A to subscribe to an event on form-B, but still allow form-A to be garbage collected if it were closed first. Normally, if form-A were closed, it would still hang around in memory because the fact that it's subscribed to an event means there's still a reference to it hanging around.
Really, I would argue that most or all event should be weak references.
The MSDN description is fairly informative and includes a hypothetical example.