Răsfoiți Sursa

fixed memory leak in compilation server, added regular Gc.compact()

Nicolas Cannasse 13 ani în urmă
părinte
comite
c2a8142ada
2 a modificat fișierele cu 13 adăugiri și 1 ștergeri
  1. 12 0
      main.ml
  2. 1 1
      type.ml

+ 12 - 0
main.ml

@@ -479,6 +479,7 @@ and wait_loop boot_com host port =
 		with Not_found ->
 		with Not_found ->
 			None
 			None
 	);
 	);
+	let run_count = ref 0 in
 	while true do
 	while true do
 		let sin, _ = Unix.accept sock in
 		let sin, _ = Unix.accept sock in
 		let t0 = get_time() in
 		let t0 = get_time() in
@@ -544,6 +545,17 @@ and wait_loop boot_com host port =
 			if verbose then print_endline "Connection Aborted");
 			if verbose then print_endline "Connection Aborted");
 		if verbose then print_endline "Closing connection";
 		if verbose then print_endline "Closing connection";
 		Unix.close sin;
 		Unix.close sin;
+		(* prevent too much fragmentation by doing some compactions every X run *)
+		incr run_count;		
+		if !run_count mod 1 = 50 then begin
+			let t0 = get_time() in
+			Gc.compact();
+			if verbose then begin
+				let stat = Gc.quick_stat() in
+				let size = (float_of_int stat.Gc.heap_words) *. 4. in
+				print_endline (Printf.sprintf "Compacted memory %.3fs %.1fMB" (get_time() -. t0) (size /. (1024. *. 1024.)));
+			end
+		end
 	done
 	done
 
 
 and do_connect host port args =
 and do_connect host port args =

+ 1 - 1
type.ml

@@ -318,7 +318,7 @@ let null_class =
 	c
 	c
 
 
 let add_dependency m mdep =
 let add_dependency m mdep =
-	m.m_extra.m_deps <- PMap.add mdep.m_id mdep m.m_extra.m_deps
+	if m != null_module then m.m_extra.m_deps <- PMap.add mdep.m_id mdep m.m_extra.m_deps
 
 
 let arg_name (a,_) = a.v_name
 let arg_name (a,_) = a.v_name