You aren't expecting your gain/loss or shown elevation to match when you get back to your starting point are you? It won't if the atmospheric pressure is changing as it always is.
A .1 in. Hg change in barometric pressure is 100 feet of elevation change. The baro sensor in your device has no way of knowing whether the pressure differences it senses is from it changing altitude or simply the atmospheric pressure changing. The are some ways for it to guess and some devices let you help it by adding elevation points. But some devices only adjust once for elevation.
I've had some longer rides where the elevation shown starting and finishing in the same place was 500 or more feet different. I think I've even had a ride where a dry front passed and there was almost a 1000 feet difference. Wish I'd marked those so I could show an example.