Why do the boundary terms vanish for a function in Hilbert Space?

Below I have attached a solution to a problem from a quantum mechanics textbook, and I'd simply like someone to explain why the boundary terms vanish in Hilbert Space for the functions $$f(x)$$ and $$g(x)$$, all I know is that a Hilbert space is a vector space where an inner product is defined, and that wavefunctions live in Hilbert space. If need be I can include the whole question but I thought that this snippet of the solution would be enough for my question to get answered:

Integrating by parts (twice): $$\int_{-\infty}^{\infty} f \cdot \frac{d^2 g}{d x^2} d x=\left.f^* \frac{d g}{d x}\right|_{-\infty} ^{\infty}-\int_{-\infty}^{\infty} \frac{d f^*}{d x} \frac{d g}{d x} d x=\left.f^* \frac{d g}{d x}\right|_{-\infty} ^{\infty}-\left.\frac{d f^*}{d x} g\right|_{-\infty} ^{\infty}+\int_{-\infty}^{\infty} \frac{d^2 f^*}{d x^2} g d x$$

But for functions $$f(x)$$ and $$g(x)$$ in Hilbert space the boundary terms vanish, so $$\int_{-\infty}^{\infty} f \cdot \frac{d^2 g}{d x^2} d x=\int_{-\infty}^{\infty} \frac{d^2 f^*}{d x^2} g d x$$, and hence (assuming that $$V(x)$$ is real): $$(j \mid \hat{H} g)=\int_{-\infty}^{\infty}\left(-\frac{\hbar^2}{2 m} \frac{d^2 f}{d x^2}+V f\right)^{\cdot} g d x=\langle\hat{H} f \mid g\rangle .$$

• Probably related: physics.stackexchange.com/q/160972/25301 Commented Mar 9 at 17:02
• You should include the question itself, too. In any case, it is not true that a generic $L^2$ function vanishes at infinity. But since you consider functions which are in the domain of the momentum operator, this in fact holds. THere are questions and answers here on PSE already regarding this. Commented Mar 9 at 17:35