cudaMemGetInfo is giving strange numbers for total memory

I’m using cudaMemGetInfo like this

size_t freeMem; size_t totalMem;

cudaError_t memInfo = cudaMemGetInfo(&freeMem, &totalMem);

and sometimes totalMem is different. My device has a gigabyte of global memory but sometimes cudaMemGetInfo says that it has 1041 MB sometimes 994 MB, sometimes 1001 MB. I am not talking about freeMem but totalMem in the code above. How can the total global memory change? Can someone explain this?

Also between kernel calls does the global memory get erased even if I don’t explicitly deallocate all my variables or does this only happen when the computer is rebooted?

The memory is returned to the free pool when you deallocate it, or when your program exits.