How to determine the number of instances of a class at any given point of time?