I read something about the Weakreference Class in C#, but I´m not sure about the usage of it.
I have a huge table with over 10 or 20k entries. When I write for example a List DBFoos, where Foo are objects from the database.
Where is the advantage of using Weakreference instead of Factory/Singelton Pattern if the user does read only and the pattern is only for the communitation between the classes, because the download of objects takes a while?
Edit
I found an example on MSDN
They use a Weakreference Dictionary like:
public class Cache
{
// Dictionary to contain the cache.
public static Dictionary<int, WeakReference> _cache;
If I set in this Cache my Object with the List instead of using a Singelton Like:
public class Foo{
private static Foo foo;
static Foo getreference(){
if(foo == null){
foo = new Foo();
return foo;
}
else
return foo;
}
}
Is there any advantage or disatvantage like collecting by the GC with using Weakreference or is it only a complex way of saving it ?