debub_gc (coming from the command line) indicates that gc should be
forced on program exit. Instead of sticking it on every exit path,
register it as an at_exit hook once.
Signed-off-by: Roman Kagan <rkagan(a)virtuozzo.com>
---
v2v/v2v.ml | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 7c47ea0..9cb4a27 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -55,6 +55,9 @@ let rec main () =
printf "%s: %s %s (%s)\n%!"
prog Config.package_name Config.package_version Config.host_cpu;
+ if debug_gc then
+ at_exit (fun () -> Gc.compact());
+
message (f_"Opening the source %s") input#as_options;
let source = input#source () in
@@ -63,8 +66,6 @@ let rec main () =
printf (f_"Source guest information (--print-source option):\n");
printf "\n";
printf "%s\n" (string_of_source source);
- if debug_gc then
- Gc.compact ();
exit 0
);
@@ -457,9 +458,6 @@ let rec main () =
message (f_"Finishing off");
delete_target_on_exit := false; (* Don't delete target on exit. *)
- if debug_gc then
- Gc.compact ()
-
and inspect_source g root_choice =
let roots = g#inspect_os () in
let roots = Array.to_list roots in
--
2.4.3