The third number, the maximum number of file descriptors permitted, does not change while the system is running.
It isn't usually the case that this maximum number of file descriptors have all been allocated. That's why the first number is usually much smaller than the third number. New file descriptors are allocated as needed.
Let's say a process requests a file descriptor (by opening a file). Let's suppose that the second number, the total number of file descriptors which have already been allocated but are not currently being used, is greater than 0. Then one of these will be used for this request, and the first number (the number of allocated file descriptors) will not change, because a new file descriptor did not need to be allocated for this request. Instead, the second number would decrease by 1.
But let's suppose instead that the second number is 0. This would mean that all file descriptors which have been allocated are currently in use. In that case, the second number would be already be zero, so the OS doesn't decrease it by 1. Instead, the OS allocates a new file descriptor, and increases the first number by 1.
The OS never deallocates a file descriptor while it's running. When a process closes a file descriptor, that file descriptor becomes available for either the same process (while it exists) or another process. So it doesn't "hang on" to the process until reboot.
Try this shell script on a system that's quiet, that's not running very much:
cat /proc/sys/fs/file-nr < /dev/null
When I tried it, I got these numbers:
1242 363 13107
1242 362 13107
1242 363 13107
See? When the shell script closed /dev/null
, the second number increased by 1, and the file descriptor was made available for any process for use.
Hope this helps.