Fix leaking classes related issue #1477