Sand goby males look after the eggs from multiple females, which then go off looking for more mates. The eggs are buried safely in the sand and the males keep a careful eye on them, however in some circumstances they will eat their offspring. Research by Ashley Chin-Barstaard (an unfortunate name which sounds as though it ought to apply to the cannibal fish rather than a researcher), of Purdue University, has been investigating the circumstances that causes the cannibalism.
Her research has shown that the trigger appears to be the presence of an egg predator such as a brown shrimp. This causes the male goby to eat the eggs before the shrimp has a chance to get at them. There is a long summer breeding season for the gobies, so it looks as though they eat their eggs to recoup some of their investment in them in the form of food, knowing they still have time to breed again.
Smaller males, who presumably need all the energy they can get, were found to be more likely to eat their eggs than larger males. However sickly males were less likely to eat their eggs, which may be because males with eggs are more likely to attract females.
There is an article on this on the New Scientist website.