(I could still be wrong in the following post, please correct me in this case)

Quote:
If you declare structures and/or array pointers as local variables, and fill them using
creation functions (eg str_create), does the contents of those pointers get purged on the function
closing/terminating or does the contents become "leaked memory" (as I understand is the case).
Does it vary between pointer types or anything if I am wrong?
I believe it becomes leaked memory, because everything you allocate (using str_create, ent_create or even vector()) is pasted in the memory heap while local variables are stored in the stack.
And according to some random website:
Quote:
  • storage objects in stack storage die (are deallocated) when the stack frame is popped.
  • storage objects in heap storage must be explicitly killed in C, but in other languages are implicitly killed when they are no longer referenced
The former meaning everything within the function's stack frame is killed when the function ends (local variables etc.). The latter one meaning you need to delete the memory manually (implicitly killing memory when there is no reference pointer is called garbage collection, not standard in lite-c). Since allocating memory goes into the heap, you need to kill it manually with free(). So indeed you're missing a free(TempData); in your function smile. (as well as a return type since you return a var).

ref: http://www.cs.jcu.edu.au/Subjects/cp2003/1997/foils/heapAndStack/heapAndStack.html


Gr, Joozey


Click and join the 3dgs irc community!
Room: #3dgs