Page 1 of 1

Question about when to free lists created inside procedures

Posted: Sat Dec 21, 2024 1:59 pm
by Quin
I have a procedure that declares a protected list, like so:

Code: Select all

Protected NewList Commands.s()
It then uses this list, populating it and then doing some other operations, before the function returns. My question is, do I need to call FreeList() before my function returns, or does the list going out of scope automatically free it? I.e., does calling NewList multiple times across multiple procedure calls leak memory if you don't call FreeList()?
Thanks!

Re: Question about when to free lists created inside procedures

Posted: Sat Dec 21, 2024 2:11 pm
by AZJIO
Everything will be deleted automatically. Someone already answered this question. At the end of the function, a constant is created that forces the function to delete the list before exiting.

Re: Question about when to free lists created inside procedures

Posted: Sat Dec 21, 2024 3:34 pm
by Fred
Everything is freed when a procedure ends except dynamic allocated memory with AllocateMemory or AllocateStructure. Also API usage isnt managed

Re: Question about when to free lists created inside procedures

Posted: Sat Dec 21, 2024 8:17 pm
by Quin
Thanks AZJIO and fred, all makes sense! :)