Skip to content

Commit

Permalink
Merge pull request #288 from jmid/remove-get-instances
Browse files Browse the repository at this point in the history
Remove QCheck2.TestResult.get_instances to address memory leak
  • Loading branch information
jmid authored Jul 4, 2024
2 parents 53476ad + 55b3f85 commit 2ca480c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## NEXT RELEASE

- ...
- Remove `QCheck2.TestResult.get_instances` as retaining previous test inputs
cause memory leaks

## 0.21.3

Expand Down
8 changes: 1 addition & 7 deletions src/core/QCheck2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1354,9 +1354,6 @@ module TestResult = struct
collect_tbl: (string, int) Hashtbl.t lazy_t;
stats_tbl: ('a stat * (int, int) Hashtbl.t) list;
mutable warnings: string list;
mutable instances: 'a list;
(** List of instances used for this test, in no particular order.
@since 0.9 *)
}

let get_state {state; _} = state
Expand Down Expand Up @@ -1391,8 +1388,6 @@ module TestResult = struct

let warnings = get_warnings

let get_instances r = r.instances

let is_success r = match r.state with
| Success -> true
| Failed _ | Error _ | Failed_other _ -> false
Expand Down Expand Up @@ -1763,7 +1758,6 @@ module Test = struct
and check_state_input state input_tree =
let Tree.Tree (input, _) = input_tree in
state.handler state.test.name state.test (Collecting input);
state.res.R.instances <- input :: state.res.R.instances;
collect state input;
update_stats state input;
let res =
Expand Down Expand Up @@ -1835,7 +1829,7 @@ module Test = struct
res = {R.
state=R.Success; count=0; count_gen=0;
collect_tbl=lazy (Hashtbl.create 10);
instances=[]; warnings=[];
warnings=[];
stats_tbl= List.map (fun stat -> stat, Hashtbl.create 10) cell.stats;
};
} in
Expand Down
4 changes: 0 additions & 4 deletions src/core/QCheck2.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1610,10 +1610,6 @@ module TestResult : sig
(** [get_warnings t] returns the list of warnings emitted during the test.
@since 0.18 *)

val get_instances : 'a t -> 'a list
(** [get_instances t] returns the generated instances, with no guarantee on the order.
@since 0.18 *)

val is_success : _ t -> bool
(** Returns true iff the state is [Success]
@since 0.9 *)
Expand Down

0 comments on commit 2ca480c

Please sign in to comment.