Loss of coherence and memory effects in quantum dynamics