Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

weak references in .net

Can someone give some examples of using weak references in .net projects ?

like image 357
void Avatar asked Dec 27 '22 21:12

void


1 Answers

Think about cache with 2 levels. So objects in the 1st level are referenced with normal references and in then 2nd level with weak references. Thus if you want to expiry your object from the 1st level you can put it in the 2nd level.

Next time, when client tries to access this object if you have enough memory object will be promoted from the 2nd level, however if memory is not enough and object was collected you will have to recreate your object. Sometimes it will be recreated or retrieved from expensive store but in some situation you will be able to find it in the 2nd level.

like image 122
Andrey Taptunov Avatar answered Jan 13 '23 18:01

Andrey Taptunov