Like in this example below , consider that object A has to determine which object is closer ,object B or object C . The pink rectangle is an obstacle . Now if we consider the euclidean distance, object B will be closer but due to the presence of an obstacle euclidean distance will give false answers .
Another solution would be to find the distance using pathfinding algorithm , which will give the correct solution , but will be slow . 
What will be the ideal solution of this problem , in a game where thousands of possible target entities may be present .