File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -485,6 +485,17 @@ pub fn (a &array) free() {
485
485
C.free (a.data)
486
486
}
487
487
488
+ [unsafe ]
489
+ pub fn (mut a []string) free () {
490
+ $if prealloc {
491
+ return
492
+ }
493
+ for s in a {
494
+ unsafe { s.free () }
495
+ }
496
+ C.free (a.data)
497
+ }
498
+
488
499
// str returns a string representation of the array of strings
489
500
// => '["a", "b", "c"]'.
490
501
pub fn (a []string) str () string {
Original file line number Diff line number Diff line change @@ -2642,6 +2642,11 @@ fn (mut g Gen) autofree_variable(v ast.Var) {
2642
2642
// eprintln(' > var name: ${v.name:-20s} | is_arg: ${v.is_arg.str():6} | var type: ${int(v.typ):8} | type_name: ${sym.name:-33s}')
2643
2643
// }
2644
2644
if sym.kind == .array {
2645
+ if sym.has_method ('free' ) {
2646
+ free_method_name := g.typ (v.typ) + '_free'
2647
+ g.autofree_var_call (free_method_name, v)
2648
+ return
2649
+ }
2645
2650
g.autofree_var_call ('array_free' , v)
2646
2651
return
2647
2652
}
You can’t perform that action at this time.
0 commit comments