Why are gnats around standing fruit?

Of all the flying pests, gnats might be the most annoying. Though they're harmless, they hover and buzz around our heads, driving us crazy. Gnats are also known as vinegar flies or fruit flies because of their attraction to the smell of rotten food. This explains why they particularly enjoy the areas around drains and trash cans. Gnats are most commonly found around fruit, saturated house plants, compost piles, and other rotting, smelly food or plants. The problem is there's no such thing as one gnat. In fact, one gnat can lay two to three hundred eggs in its two to four month life span. If you frequently see gnats hovering around your sink drain or trash can, there's a good chance they're laying eggs inside your home. If you don't want gnats around, you have to cut off their food supply. This means fruits and vegetables have to go in the refrigerator or a bin the bugs can't penetrate. Make sure house plants stay damp, but not wet, and they must have the proper drainage. Gnats just love over-watered house plants. Empty trashcans regularly and don't allow rotting food to sit in the house. Make sure all trash receptacles and sink drains are cleaned thoroughly, and don't have any old rancid food stuck to them. Never let dirty dishes stand in the sink.