glTexImage2D - uploading a new image for the same texture id

Here is an example code:

//img1 2048x2048
//img2 1024x1024

glGenTextures(1, &texId);

glBindTexture(GL_TEXTURE_2D, texId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img1.getWidth(), img1.getHeight(), 0, GL_BGR, GL_UNSIGNED_BYTE, img1.accessPixels());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);

glBindTexture(GL_TEXTURE_2D, texId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img2.getWidth(), img2.getHeight(), 0, GL_BGR, GL_UNSIGNED_BYTE, img2.accessPixels());
glBindTexture(GL_TEXTURE_2D, 0);

As you can see I use the same texture id for uploading two different images. I use nvidia-smi for monitoring gpu memory usage. A memory used by the texture equals 20 MiB. It doesn’t matter which image is uploaded first. If I call a second glTexImage2D just after the first one without rebinding a texture then memory usage equals 4 MiB:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img1.getWidth(), img1.getHeight(), 0, GL_BGR, GL_UNSIGNED_BYTE, img1.accessPixels());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img2.getWidth(), img2.getHeight(), 0, GL_BGR, GL_UNSIGNED_BYTE, img2.accessPixels());

Does it mean that opengl doesn’t free a memory when other image is uploaded with the same texture id after rebinding a texture ?