Use a WeakReference to cache class loaders

Fixes #171