Fix memory lifetime management for JavaCV.