Fix gmagick memory leak

We need to unset gmagick instance to free memory. And unset layers instance because it contains reference to gmagick too.
I'm not sure. As I see, this problem happens only when we use Gmagick.
But the thing I know for sure, this bug is critical, this library without fix cannot be used at all.