For loop should be a while and client list must be cleared in onResourceRelease().

This commit closes #2220.