In order to understand how this script works, we must focus on the selection mask, that is the channel related to the selection (you can view it either by activating Quick Mask or by saving the selection as a channel). Referring to this mask, the script eliminates every area that is composed from non-white pixels and is completely enclosed by a fence of white pixels; since the elimination consists in filling such areas of the mask with white, the corresponding holes of the selection will disappear.
Therefore, a black and gray region contiguous to the image's borders across at least one pixel is not supposed to be a hole, because not all of its edges are adjacent to white pixels.
With the purpose of being more powerful, the script also provides two options for adjusting the selection before the real removal operates.
When the option called 'Normalize selection at first' is on, the contrast of the selection mask is stretched so that the lightest pixels become white and the darkest pixels become black; this way, it's often possible to remove some holes even from selections whose masks are devoid of white pixels, which are essential for circumscribing every eliminable hole. The example hereunder shows how this initial improvement helps at least to eliminate certain holes (the ones of the letters G and M) which you couldn't remove without it instead.
By activating the option called 'Apply threshold to selection at first', the selection mask will be transformed into a black and white channel without antialiasing; the extent of white areas can be regulated with the slider called 'White threshold'. This feature is useful to boost the action of removal, especially when the selection has got soft borders and blurred zones, as shown in the illustration below.
Once installed, you can launch this script from the image menubar through
'Select -> Remove Holes...'.