The collapse of nanobubbles in water