I have never seen such an example. I would probably do something like:
class Resource {
static Resource Instance = new Resource();
static int count = 2;
public Resource CheckOut() {
if (--count <= 0)
Instance = null;
return Instance;
}
}
Thus, after checking the ClassA and ClassB resource, the static link ceases to support it. After ClassA and ClassB lose the link to the resource, the finalizer receives the next round of garbage collection.
source
share