Memory leaks in ion?

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.

Edited by John Cleary on Reason: Initial post
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.