Air locks and saving air in Mars habitats and vehicles

This OP is inspired by the film The Martian, but I think it belongs here in GQ because I’m asking about how this problem would be solved in the real world.

In the film, the astronaut goes in and out of the habitat and the rover vehicle multiple times, through an airlock in the former case. WRT to the latter, I don’t recall seeing how the vehicle is pressurized or depressurized, but he is shown in there without a helmet.

It seems to me that in both those situations it would be very wasteful of a relatively rare resource – breathable air – to just exhaust the air in the airlock or the vehicle to the outside when getting in or out. OTOH, it obviously would take much more time and energy to pump the air into a tank to save it.

I’ve just bought the book, but haven’t gotten past the first few pages yet, so I don’t know if the author deals with this particular issue, but as I said, I’m more interested in how this would be handled on a real Mars or Moon mission.

Would they take the time to save the air, and if so, how long would it take to evacuate an airlock or a rover vehicle about the size shown in the film? Or could they synthesize and replenish the nitrogen and oxygen needed for a breathable atmosphere, and therefore afford to waste air?

Presumably the habitat might very well have enough space and energy for the equipment needed to extract the elements from the local environment to make air. But the rover would have to carry tanks of air, and if it was expected to be traveling and self-sufficient for many sols (as seen in the film, and, I assume, in the book) and many depressurization/pressurization cycles, could they afford not to preserve the air? But wouldn’t saving it be a significant drain on the rover’s power, which must also be rather limited?

I assume real engineers have done some work on these scenarios, and would love to know how they would be dealt with. Calling Stranger on a Train…?

IIRC, in both the book and the movie, the hab’s air is pumped back into the hab, and the smaller volume of air is evacuated out of rover when opened, but re-pressurized quickly when he seals it.

It’s not really addressed in the movie much, but he has a piece of technology that can separate the oxygen from Mars’ carbon dioxide atmosphere. So, really, he’s got all the oxygen he needs, provided he keeps that equipment running. On the Moon, you don’t have this option of course (other than the oxygen you bring, and using CO2 scrubbers to regain some oxygen).

I can’t remember how Andy Weir addressed the O2 mix for the hab/rover as 100% O2 would be very problematic. If they did bring nitrogen, they’d only have so much. However, he could have retrieved plenty of nitrogen when he catalyzed the hydrazine when he had to create more hydrogen to make water.

Here.

Aren’t the hatches themselves deigned to use the internal pressure to seal?

Mars’s atmosphere is about 1.9% N2 and 0.14% O2 according to Wikipedia. So if they can pull O2 out if it, then they can pull plenty of N2 out as well.