nset reference variable after looping by reference for components, modules and templates

- When looping by reference, reference variable is not unset at the end of the loop.
- and a bit CodeStyle

see: https://github.com/joomla/joomla-cms/issues/5482