I’ve been noticing high memory usage in a CSV scanning program I’m writing. After enabling debug I am now seeing “Allocations Not Freed” errors with string operations within a loop. Since I’m just getting started with Odin I’m not sure if it’s something I’m doing wrong, or if there are small leaks (typically < 200 bytes) within the strings package itself?
The variables I’m putting things into are defined as:
csv_line_struct :: struct {
filepath : string,
filebytes : u64,
filedate : time.Time,
filecount : u64
}
csv_input_line : csv_line_struct
work_filepath : string
The “r” below is a csv.iterator_next row, and inside the loop for that I’m doing (possibly awful) things to chop up various CSV fields, such as:
work_filepath = strings.trim(strings.split(r[0],"/")[1],"/. ")
csv_input_line.filepath = strings.clone(work_filepath)
csv_input_line.filebytes, _ = strconv.parse_u64_of_base(r[1],10)
workmonth, _ = strconv.parse_uint(strings.split(r[2],"/")[0])
workday, _ = strconv.parse_uint(strings.split(r[2],"/")[1])
workyear, _ = strconv.parse_uint(strings.split(r[2],"/")[2])
Later on I append that csv_input_line to an output array of csv_line_struct. I had to do the strings.clone because I discovered if I didn’t then that string field didn’t survive exiting the iterator loop and became garbage for…reasons?
Every line above has a leak except the “csv_input_line.filebytes” one.
I’m hoping this is just some rookie crap on my part, so forgive me in advance.
FYI - the small CSV test case for this is only about 100,000 lines, however the ultimate final run is against a nearly 300m row CSV file (yikes, I know) so even small leaks add up super-quickly in that scenario, into many many dozens of GB of bloat.