Page 1 of 1
Does a LinkedList/Map automatically get released on end?
Posted: Fri Dec 16, 2011 1:07 pm
by Env
Just a quick question;
If you create a structured LinkedList or Map (Either standalone, or part of a structure) do they automatically get released (memory freed) upon program end, or they lose scope (defined in a procedure)?
Just want to be sure,
Thanks

Re: Does a LinkedList/Map automatically get released on end?
Posted: Fri Dec 16, 2011 1:56 pm
by Trond
All memory is freed automatically when the program ends.
At the end of the procedure, all linked lists and maps are freed automatically. But manually allocated memory is not freed. So if you have a structured linked list with pointers inside the structure, the memory pointed to by the pointers is not freed.
Edit:
http://purebasic.fr/english/viewtopic.php?f=13&t=48468
Edit: With pointers it must be freed:
Code: Select all
Structure Struct
*Memory.Character
EndStructure
Procedure Test()
NewList L.Struct()
AddElement(L())
L()\Memory = AllocateMemory(1000)
AddElement(L())
L()\Memory = AllocateMemory(555)
AddElement(L())
L()\Memory = AllocateMemory(789)
; Free allocated memory
ForEach L()
FreeMemory(L()\Memory)
Next
; List elements are deleted automatically
EndProcedure
Re: Does a LinkedList/Map automatically get released on end?
Posted: Fri Dec 16, 2011 2:23 pm
by Env
I presumed as much, but always good to get confirmation.
Thanks
