v icon indicating copy to clipboard operation
v copied to clipboard

V initialises unused modules

Open clubby789 opened this issue 4 years ago • 7 comments
trafficstars

V version: V 0.2.2 82650ee

What did you do?

module main

import net.http

fn main() {
    println('hi')
}
[ ... ]
v -autofree test.v
valgrind ./test

What did you expect to see? No memory leaks

What did you see instead?

==3818== HEAP SUMMARY:
==3818==     in use at exit: 199 bytes in 7 blocks
==3818==   total heap usage: 4,608 allocs, 4,601 frees, 174,297 bytes allocated

The generated C code contains initialisation blocks for net.openssl, os, net.urllib etc. As well as initialising modules that the compiler recognises as unused, autofree fails to free these allocations.

clubby789 avatar Feb 14 '21 13:02 clubby789

Try again with -skip-unused. WIP for now, but will be the default in the future.

JalonSolov avatar Feb 14 '21 16:02 JalonSolov

What's the reason for it being WIP? I'd be interested in contributing if there's some kind of issue tracking the feature.

clubby789 avatar Feb 14 '21 20:02 clubby789

The reason for it being WIP is because it isn't finished, yet. :-)

JalonSolov avatar Feb 14 '21 20:02 JalonSolov

What I meant was what are the specific parts of the problem that are currently unsolved, because I'd be interested in helping out.

clubby789 avatar Feb 14 '21 21:02 clubby789

I'm not working on it, so I don't know. You'll have to wait for someone who has been working on it to respond. Or, take a look at the source and see if you can tell what is/isn't being done now.

JalonSolov avatar Feb 14 '21 21:02 JalonSolov

Actually @clubby789 I wonder if that is even an issue.

Such code wouldn't even compile in Go (unused import). V has a similar warning, and vfmt can simply remove an unused import.

During dev stage it doesn't matter if init is called from the module you're going to use anyway.

medvednikov avatar Feb 16 '23 15:02 medvednikov

@medvednikov wouldn't that affect e.g. some tests? Tests could be sensitive to memory leaks and such and it is not a good idea to conditionally compile different tests for production builds and non-prod builds/runs.

dumblob avatar Feb 16 '23 20:02 dumblob