I have written the attached patch to handle the deletion of native compilation units still in use. I have tested that it works well.