Memory allocated by alloca is allocated on the stack and will automatically be freed at the end of the function, not scope.
Do not call free on this memory. Do not allocate more than a few bytes using alloca or you will risk a stack overflow leading to undefined behavior.
For automatic garbage collection, use C++ smart pointers or Rust instead.
On Windows you also have:
_malloca
_calloca
These are not portable so I wouldn't use them. They are a safer version of alloca which allocates to the heap if there isn't enough stack space. However, you need to free them using _freea which eliminates the main benefit of alloca.
As far as I can tell, the only benefit is to prevent heap fragmentation.