We present a study of the elemental depletion in the interstellar medium. We combined the results of a Galatic model describing the gas physical conditions during the formation of dense cores with a full-gas-grain chemical model. During the transition between diffuse and dense medium, the reservoirs of elements, initially atomic in the gas, are gradually depleted on dust grains (with a phase of neutralisation for those which are ions). This process becomes efficient when the density is larger than 100~cm$^{-3}$. If the dense material goes back into diffuse conditions, these elements are brought back in the gas-phase because of photo-dissociations of the molecules on the ices followed by thermal desorption from the grains. Nothing remains on the grains for densities below 10~cm$^{-3}$ or in the gas-phase in a molecular form. One exception is chlorine, which is efficiently converted at low density. Our current gas-grain chemical model is not able to reproduce the depletion of atoms observed in the diffuse medium except for Cl which gas abundance follows the observed one in medium with densities smaller than 10~cm$^{-3}$. This is an indication that crucial processes (involving maybe chemisorption and/or ice irradiation profoundly modifying the nature of the ices) are missing.