cyclic dependency resulting in memory leak with shared_ptr solved