Question about when to free lists created inside procedures

Just starting out? Need help? Post your questions and find answers here.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Question about when to free lists created inside procedures

Post 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!
AZJIO
Addict
Addict
Posts: 2224
Joined: Sun May 14, 2017 1:48 am

Re: Question about when to free lists created inside procedures

Post 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.
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Question about when to free lists created inside procedures

Post by Fred »

Everything is freed when a procedure ends except dynamic allocated memory with AllocateMemory or AllocateStructure. Also API usage isnt managed
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Question about when to free lists created inside procedures

Post by Quin »

Thanks AZJIO and fred, all makes sense! :)
Post Reply