Task Manager -> RAM tab -> Clear memory button
The phone warns about gracefully closing applications before doing that. However I did not think it would affect WiFi, like it never affected the ability to connect to 3G or make a voice call. This may be an implementation issue in the Samsung phone I use. After I stopped clearing the used memory, the issue has not recurred.
Before coming up with this observation I also reported the issue to Samsung tech support on phone. As expected, initially the tech support started doubting trivial things without even completely understanding my issue. They promised to get back and I'm yet to hear (4 days and counting)...