#Memory leak

1 messages · Page 1 of 1 (latest)

finite lagoon
#

I am pretty new to Odin an am writing compiler as a learning project. I came to a problem with memory leak warnings that I cannot solve. In the image is one of the procedures where the memory leak happens, specifically in strings.clone() line. But I don't know how to solve this because I cannot just defer delete this string. I am thinking either the whole code structure is not correct or I need to use some memory stuff like allocators?

static ridge
#

The general structure is fine, that just means whoever calls the proc needs to delete the string when they're done with it

finite lagoon
#

so i need to delete it in test method? But this is 3 procedures deep

static ridge
#

It has to be deleted somewhere. The alternative would be to use a temporary allocator (e.g. context.temp_allocator) so that you can free everything allocated with that allocator at once without needing to do it individually (free_all(context.temp_allocator)). That also works for tests, it won't complain about things in the temp_allocator

umbral plover
#

if the file has a long enough lifetime you could also just store a slice instead of cloning it

haughty light
#

You can remove the builder destroy and just not clone the string

#

If you ensure that each Token has an allocated string (not a literal) then you could write a destroy_token or adjacent procedure for the caller to handle