Cleanup weakrefs before handling finalizers

If weakrefs are kept alive because of finalizers, this means that people
can access finalized objects if they use finalizers. This shouldn't
happen and can cause problems, for example with therubyracer.

This problem occured with therubyracer which resulted in an exception
with the message "Data object has already been freed" because it
expects the object to be usable if it can be referenced through a
weakref.