Fixed a bug with java:terminate and gc handling.