Implement onclose callback, add missing decrefs