If
you think about it you can't lose heat in a vacume because molocules
have nothing to transfer heat energy to. Unless space isn't a total
vacume...
Molecules can transfer heat by radiation. There are three ways to transfer heat: conduction, convection and radiation. You're right that heat can't be lost through conduction and convection in space. Radiative heat transfer loses heat by photon emission, rather than requiring molecules to be in contact with each other. This is how heat is transferred through space, including how we receive heat from the Sun. It's also the reason that the glass flask inside a Thermos-style flask is coated in silver paint, to reflect the radiated heat back into the liquid inside, thereby keeping it warmer for longer.
As a side note, space isn't actually a perfect vacuum. There are particles of matter flying through space. Between the galaxies, there is very little gas and dust, but inside galaxies there are nebulae and dust clouds and such. In the Solar System, for example, there are comet trails and the solar wind. The solar wind gives rise to aurora when it hits the Earth's atmosphere, so it is fair to say that it could cause conductive heating if it were to hit some space-object. The density of such matter even in the Solar System is low, though, and it mostly travels fast enough that it would likely cause heating rather than cooling, if it were to have any effect.