IMO, if you're going to be having sex this is something you should discuss with your partner so that you agree on the matter.

I know that's not exactly how it always happens but that's how I think it should be done.

And yes, a man can walk away. As someone said he can forfeit all his parental rights and I believe both of you can also sign something saying that he wants nothing to do with the child and you agree to not go after him later for support.