Changed implementation of ref counter from shared ptr to allocated ptr with instance memory leak check