Avoid possible GC issues in Java example code

This prevents the previously-set element value from being collected
before or during the call to setElement. Since C++ could still have
a reference to during that time, it could lead to misbehavior.
1 file changed