GaN is an important semiconductor for energy-efficient light-emitting devices. Hydrogen plays a crucial role in gallium nitride (GaN) growth and processing. It can form electrically neutral complexes with acceptors during growth, which significantly increases the acceptor incorporation. Post-growth annealing dissociates these complexes and is widely utilized for activating Mg acceptors and achieving conductive p-type GaN. In this work, we demonstrate that other acceptors, such as C and Be, also form complexes with hydrogen similar to Mg. The effect of thermal annealing of GaN on photoluminescence (PL) was investigated. In samples moderately doped with Be, the Be-Ga-related yellow luminescence (YLBe) band intensity decreased by up to an order of magnitude after annealing in N-2 ambient at temperatures T-ann = 400 degrees C-900 degrees C. This was explained by the release of hydrogen from unknown traps and the passivation of the Be-Ga acceptors. A similar drop of PL intensity at T-ann = 350 degrees C-900 degrees C was observed for the C-N-related YL1 band in unintentionally C-doped GaN and also attributed to passivation of the C-N acceptors by hydrogen released from unknown defects. In this case, the formation of the CNHi complexes was confirmed by the observation of the rising BL2 band associated with these complexes. At T-ann > 900 degrees C, both the YLBe and YL1 intensities were restored, which was explained by the removal of hydrogen from the samples. Experimental results were compared to the first principles calculations of complex dissociation and hydrogen diffusion paths in GaN.