We have leased cars before and have both bought and walked away at the end. The time we bought the car at the end of the lease we did OK, but might have done better had we purchased the car up front. The catch is that with our cash flow, we could not do that, so it worked out OK for us -- allowing us to have a car at a reasonably monthly cost. We had planned to walk away at the end, but we really liked the car and the price was reasonable.
The time we really did walk away, we knew ahead of time that we were going to do that, so we were OK with how it all turned out.
The dealer is not going to lose money in any deal. In a purchase deal, you take out a loan, and the dealer gets paid. In a lease, an leasing agency takes out the loan, and the dealer gets paid. The dealer makes out OK either way. It's in the dealer's best interest to sell you a car regardless of how it's paid for. I think (but I am not sure) that the dealer makes out a little better with a lease.
In general, we prefer to own, but that is not always possible, or reasonable