Explicitly drop `obj` when it is no longer needed to avoid borrow errors, and add a test case similar to #3169. Co-authored-by: Mike Welsh <mwelsh@gmail.com>