Fix gmagick memory leak

We need to unset gmagick instance to free memory. And unset layers instance because it contains reference to gmagick too.
After calling unset($this->gmagick) line null !== $this->gmagick will throw a notice.