Does a LinkedList/Map automatically get released on end?

Everything else that doesn't fall into one of the other PB categories.
Env
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 27, 2010 3:20 pm
Location: Wales, United Kingdom

Does a LinkedList/Map automatically get released on end?

Post 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 :)
Thanks!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Does a LinkedList/Map automatically get released on end?

Post 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
Env
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 27, 2010 3:20 pm
Location: Wales, United Kingdom

Re: Does a LinkedList/Map automatically get released on end?

Post by Env »

I presumed as much, but always good to get confirmation.

Thanks :)
Thanks!
Post Reply