Implement link counting for debugging