Free up memory before disabling gc.