4. Let $a, b, c$ be the sides opposite to the interior angles $A, B, C$ of $\triangle A B C$, respectively, and the area $S=\frac{1}{2} c^{2}$. If $a b=\sqrt{2}$, then the maximum value of $a^{2}+b^{2}+c^{2}$ is . $\qquad$
4. 4

Analysis: Since $S=\frac{1}{2} c^{2}=\frac{1}{2} a b \sin C, a b=\sqrt{2}$, thus $c^{2}=\sqrt{2} \sin C$, hence $c^{2}=\sqrt{2} \sin C=a^{2}+b^{2}-2 \sqrt{2} \cos C$, so $a^{2}+b^{2}=2 \sqrt{2} \cos C+\sqrt{2} \sin C$, therefore $a^{2}+b^{2}+c^{2}=2 \sqrt{2} \cos C+\sqrt{2} \sin C+\sqrt{2} \sin C=4 \sin \left(C+\frac{\pi}{4}\right) \leq 4$, equality holds when $C=\frac{\pi}{4}$, $A=\frac{\pi}{4}$, $B=\frac{\pi}{2}$ or $C=\frac{\pi}{4}$, $B=\frac{\pi}{4}$, $A=\frac{\pi}{2}$.