How to prevent getting easily attached to people?

I rarely put my walls down with people, but when I do - I attach easily.

Like my friend, who lived with me for about a month just left and we both cried.

I didn’t know she became so precious to me until after she left.

I even disliked some of her traits but now that I am going to go back home and she won’t be there, I feel a bit sad.

Updates
+1 y
Now that she left and I have more time by myself and more time for thinking, I start missing my ex again.

I just want to get to the point where I don’t miss anyone.
How to prevent getting easily attached to people?
Post Opinion