mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
autofree: free references
This commit is contained in:
parent
44ec8a8cd4
commit
6d47dd22df
@ -3204,7 +3204,9 @@ fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, start_pos int, end_pos int
|
|||||||
fn (mut g Gen) autofree_variable(v ast.Var) {
|
fn (mut g Gen) autofree_variable(v ast.Var) {
|
||||||
sym := g.table.get_type_symbol(v.typ)
|
sym := g.table.get_type_symbol(v.typ)
|
||||||
// if v.name.contains('output2') {
|
// if v.name.contains('output2') {
|
||||||
|
if g.is_autofree {
|
||||||
// eprintln(' > var name: ${v.name:-20s} | is_arg: ${v.is_arg.str():6} | var type: ${int(v.typ):8} | type_name: ${sym.name:-33s}')
|
// eprintln(' > var name: ${v.name:-20s} | is_arg: ${v.is_arg.str():6} | var type: ${int(v.typ):8} | type_name: ${sym.name:-33s}')
|
||||||
|
}
|
||||||
// }
|
// }
|
||||||
if sym.kind == .array {
|
if sym.kind == .array {
|
||||||
if sym.has_method('free') {
|
if sym.has_method('free') {
|
||||||
@ -3241,6 +3243,8 @@ fn (mut g Gen) autofree_variable(v ast.Var) {
|
|||||||
}
|
}
|
||||||
if sym.has_method('free') {
|
if sym.has_method('free') {
|
||||||
g.autofree_var_call(c_name(sym.name) + '_free', v)
|
g.autofree_var_call(c_name(sym.name) + '_free', v)
|
||||||
|
} else if v.typ.is_real_pointer() {
|
||||||
|
g.autofree_var_call('free', v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
vlib/v/tests/valgrind/2.heap_objects.v
Normal file
13
vlib/v/tests/valgrind/2.heap_objects.v
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
struct User {
|
||||||
|
name string
|
||||||
|
age int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn simple() {
|
||||||
|
user := &User{'Bob', 31}
|
||||||
|
println('done')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
simple()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user