focus-editor / focus

A simple and fast text editor
GNU General Public License v3.0
1.82k stars 99 forks source link

Memory Leak in Build commands #335

Open jejikeh opened 7 months ago

jejikeh commented 7 months ago

Memory Leak when launch build command with excessive stdout calls

This video provides a demonstration of the issue.

In the C version of the test, the editor does not crash, but RAM usage increases dramatically from 300MB to 5GB within seconds. Additionally, I attempted to rerun the build command with the clear_build_output_before_running option enabled, but this did not resolve the issue.

Go version of the program crashes Focus entirely.

Additionally, timeout_in_seconds doesn't help if it's set to more than 1 second. (I believe this may depend on the hardware.) Video

Expected behavior

In the C example, it would be acceptable if, at the very least, after terminating the build command, the RAM usage drops back to its initial level.

Regarding the Go example, I'm uncertain. If Go prints to the console at a slower rate compared to C, why does it cause the Focus to crash completely?

jejikeh commented 7 months ago

Here are the test files.

go program:

// main.go
package main

import(
    "fmt"   
)

func main() {
    for {
        fmt.Println("Hello, focus")
    }
}

build script for go:

# run-go.sh
go run main.go

c program:

// main.c
#include <stdio.h>

int main(void) {
    for (;;) {
        printf("Hello, focus\n");
    }
}

build script for c:

# run-c.sh
clang main.c

My project config for build commands

[[build commands]]

clear_build_output_before_running: true

[run c]
build_command:                    ./run-c.sh
open_panel_on_build:              true
build_working_dir:                /Users/jejikeh/Code/focus/bug-stdout
run_command:                  ./a.out
run_working_dir:                  /Users/jejikeh/Code/focus/bug-stdout
timeout_in_seconds:           5

[run go]
build_command:                    ./run-go.sh
open_panel_on_build:              true
build_working_dir:                /Users/jejikeh/Code/focus/bug-stdout
jejikeh commented 7 months ago

On Linux (Fedora 38 + GNOME), the memory usage spike still persists, but the editor stays responsive, and the timeout options work just fine.