V version: 0.1.14
OS: Windows 10
What did you do?
I ran this code:
import net
fn main() {
server := net.listen(8080)
response := 'HTTP/1.1 200 OK\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\nHello World\r\n'for { connection := server.accept() connection.recv(1024) connection.send(response.str, response.len) connection.close() }}
What did you expect to see?
Webserver should display "Hello World" when I connect to it
What did you see instead?
The webserver did not work as expected and I've seen a huge memory leak

Testing the same code under Linux shows that the webserver does work. When running load test (apache ab) with 10 concurrent connections with 2.5 million requests also shows memory growing (after several runs it uses about 4GB).
It might have to do with the tight for loop so it can't cleanup any resources (?)
The memory has to be cleaned up manually because of the infinite for loop
request = connection.recv(1024)
...
C.free(request)
@justicesuh Yes that fixes it (it stays on a constant 84KB).
Shouldn't the compiler manage such lifetimes or at least warn about the cases it cannot handle?
It should and it will. This is my next project.
@vegax87 did freeing the memory fix the server issue? if not, what browser are you using to connect to the server?
@justicesuh C.free has fixed the memory leak, but there are still 2 issues:
1) the socket isn't opening properly on Windows , because it says "connection refused" on both Firefox and Chrome
1) there's still an anomalous CPU usage around 15% after I try to connect to localhost:8080 ( btw I have 8-core CPU)
Most helpful comment
It should and it will. This is my next project.