You can probably think of at least one ex who was part of your life for a little too long. You’re not alone: A new study from Portugal suggests that there’s a reason we get trapped in bad relationships.

You might remember the “sunk cost fallacy” from Economics 101. The theory goes that the more time and money you sink into something, the harder it is to walk away. You think you’re making a rational decision, but you’re actually just too emotionally invested to see how cutting your losses could lead to better things later on.

This plays out in your love life, too, the researchers say. When people had already invested lots of time, money, and effort into a relationship, they were more likely to stick with it even when they weren’t happy.

In other words, couples were more likely to keep on trudging through the misery if they’d been together for several years, had kids, or bought a house together compared to similarly unhappy couples with shorter timelines, no kids, or fewer mutual expenses.

The researchers also concluded that it’s often men and not women who are likely to stay in a bad relationship for these reasons.

Megan Close, LMFT, a marriage and family counselor based in New York City, sees this all the time in couples counseling. Tallying time and credit card charges instead of your emotional needs “often leads to affairs, overworking, and increased separate travel,” she said.

It’s not that we’re masochists—we’re pack animals. “We’re all wired to be together,” Close says. It’s tough to break a long-standing bond. You’ve gotten used to how your partner smells and feels, and those connections are powerful.

If you’re not sure whether to call it quits, consider whether your efforts to improve the relationship are doing any good. If you and your partner have made compromises, and the relationship still isn’t working, it may be time to rip the Band-Aid off. 

Having a positive support system will help. Think about all the aspects of your life. Is your relationship the only outlier in terms of how happy you feel? “The more that you have great things going on at work, and friends, it makes it a lot easier to say ‘this doesn’t really fit in,’” Close says.

It’s not easy. “Staying together is the default,” Close says. Change is hard and messy and sad.

But knowing that and being able to look at your relationship honestly is the first step. Of course, breakups and divorce are terrible, but if you find that your main reasons sticking around are quantifiable things like the time you’ve spent together and the vacations you’ve already booked? It’s time to get out.