Fix replace method: deallocate before allocate.

When same ids are given it was not behaving correctly. It was deleting newly created circuits.
Merge pull request #930 from isartcanyameres/fix/replace-circuit-bug

When same ids are given it was not behaving correctly. It was deleting newly created circuits.