I have a class A providing Bitmaps to other classes B, C, etc.
Now class A holds its bitmaps in a ring queue so after a while it will lose reference to the bitmap.
While it's still in the queue, the same Bitmap can be checked out by several classes so that, say, B and C can both hold a reference to this same Bitmap. But it can also happen that only one of them checked out the Bitmap or even none of them.
I would like to dispose of the bitmap when it's not being needed any more by either A, B or C.
I suppose I have to make B and C responsible for somehow signaling when they're finished using it but I'm not sure about the overall logic.
Should it be a call to something like DisposeIfNowOrphan() that would be called, in this example, three times :
1 - when the Bitmap gets kicked out of the queue in class A
2 - when B is finished with it
3 - when C is finished with it
If that's the best strategy, how can I evaluate the orphan state ?
Any advice would be most welcome.