Hide instance from lambda functions

This fixes a possible memory corruption where the list of instances is
resized while another thread is trying to access an instance.
Clear events after passing them to java