There's that, and there's also the sheer math of the time for calorie in/calorie "out."
Say a slice of cheesecake gets you 325 calories. You eat it in a couple minutes. It takes like 30-40 minutes running on a treadmill to burn 325 calories. Add in a couple Famous Amos cookies and Cheetos throughout the day......nobody has any hope of spending that much time on a treadmill. You could kill yourself on it and not even break even for a day with your snacks. If you snack like I have a tendency to, anyway. And that's not even counting working off some of the regular meals, which may need to happen.
Back when I wanted to lose the 15 lbs, I was getting after it with my gym membership. I was hustling. It did all kinds of good for my greater health. But it wasn't helping me lose the pounds. My gf (now wife) told me about the uphill climb and told me the only way to get where I wanted to go was to cut back on the snacks and reduce my lunch and dinner portions.
It took several weeks, but she was right. Per usual.
Yeah, but I think it's more than that.
Let's say you're at a stable weight, and you're trying to lose weight. You *should* be able to add exercise, which should put you into calorie deficit if you change NOTHING about your diet. My point is that very few people--unless they're consciously doing it--change NOTHING about their diet.
My guess is that when you were getting after it at the gym, you were hungry, and you were
increasing your calorie intake relative to what you did before you started in the gym.
According to my Garmin app (which bases its estimate of calories on weight and heart rate from my watch), my BMR for the past year is an average of 2670 calories/day. That tracks with what various online calculators put it at for my weight, as well as the weight loss I experienced back when I counted calories, so that makes sense. But over the past year, all the exercise has meant that it is estimating that my
average total calorie burn is 3,585 per day. A little over 900 extra calories per day average due to exercise.
I've lost no weight over the last year. Because I eat whatever the hell I want, and my body wants... It wants... a lot!

If I was eating like I am now and not burning 900+ active calories a day? I'd be a fat pig. But that's not likely. If I stopped the calorie burn, I'd be less hungry, and would probably start eating less.
Your body is going to TRY to stay in balance. Which is why you can't ignore diet and only focus on exercise. Because when you burn more, you're naturally
going to eat more. Unless you actively manage it, which is what your wife told you. And, she was right. As usual...