Fix leaks by clearing registers and frame caches.