Bitwise » Forums » Memory leaks in ion?
ClearZ
John Cleary
1 posts
#15610 Memory leaks in ion?
3 weeks, 2 days ago Edited by John Cleary on June 22, 2018, 10:18 p.m. Reason: Initial post

Hi, I'm on lecture 7 and am a bit confused about the stretchy buffers (SB) that get used in the parser where the number of certain items is not known in advance. These then get copied onto the ast_arena using AST_DUP. Shouldn't the SB pointers then be freed? I don't really get why they are copied in the first place since the structs are first created on the stack, then copied into the SBs and finally copied onto the ast_arena. Seems a bit redundant or am I missing something.

John.
pervognsen
Per Vognsen
49 posts / 1 project
#15685 Memory leaks in ion?
1 week, 6 days ago

Right now I'm intentionally not cleaning up any memory since it will be handled as part of an arena once it's ported to Ion.

As for why it's copied, the reason is that some of the memory is temporary (like the memory for stretchy buffers) and some of it is persistent (like the memory for the AST). The current use cases doesn't really depend on or exploit that distinction, but once the compiler is used as a library it should be more obvious. The parser will then produce an AST (and associated data like the intern table) which will persist until the user decides to dispense with it, but any temporary memory that was used to produce it like the stretchy buffers will be immediately freed once parsing is complete.