Minecraft wiki entry for Spawn, associated text: On simulation distances 6 and higher, almost all environmentally spawned mobs immediately despawn when they are either (1) in a chunk at the edge of the simulation distance (technically, a chunk not fully surrounded by 8 chunks that were simulated on the last game tick), or (2) more than 128 blocks from the nearest player.
On simulation distance 4, mobs immediately despawn when they are more than 44 blocks from the nearest player.
Fish despawn at a shorter distance, when they are more than 40 blocks from the nearest player on all simulation distances.
Mobs more than 32 blocks from the nearest player have a 1 in 800 chance to despawn on each game tick if they have not taken damage for 30 seconds.