I do also think it is incredibly sad to give away a dog that you've had for 5 years. But sometimes life throws stuff at you that you are unable to control, I suppose.
I once was homeless for 6 weeks - couch surfing with a dog and 2yo child - because I could not find a rental where I would be allowed to keep my dog. There was no way I would've given the dog up though - no matter what - and I finally found a house where I could have her and loved the her till she died. (I didn't just go for any house either: it HAD to be somewhere with plenty of parks and ovals nearby for dogwalks!).
I did give away my cat during that time though because it was just too hard with 2 pets and I figured that the cat would adapt more easily to a new life than the dog. Still feel guilty about it, 5 years on.