Does this cleanup all memory?

Everything else that doesn't fall into one of the other PB categories.
User avatar
Kukulkan
Addict
Addict
Posts: 1415
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Does this cleanup all memory?

Post by Kukulkan »

Hello,

I'm just wondering if this is really freeing up all memory or if I create a memory-leak here?

Code: Select all

Structure structMail 
  mailaddress.s 
EndStructure 

Structure structUser
  firstName.s 
  lastName.s 
  List mailAddresses.structMail() 
EndStructure 

NewList users.structUser() 

AddElement(users())
users()\firstName = "Klaus" 
users()\lastName = "Meyer" 
AddElement(users()\mailAddresses())
users()\mailAddresses()\mailaddress = "klaus@test.de" 
AddElement(users()\mailAddresses())
users()\mailAddresses()\mailaddress = "klaus.meyer@test.de" 

ClearList(users()); everything cleaned up here?
; FreeList(users()); and is everything cleaned up here?
Is all memory cleaned up here? I'm wondering if PB is also cleaning up all mailAddresses() entries...

Kukulkan
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Does this cleanup all memory?

Post by Keya »

my understanding is that Clear clears/resets the list but it remains in memory, and Free releases the list from memory, therefore also effectively clearing it in the process
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Does this cleanup all memory?

Post by PMV »

It should, if not it would be a bug ... :?
But yes, it is intended to to free the memory of the mail-strings, too.
As PB-Linked-Lists are internally more then just a (de)allocation
of needed memory you can't assume that a tool like the windows-taskmanager
can show you if that works.

If you need to be sure the mail-adresses are not anymore as wast
in ram, i would overwrite it first.

MFG PMV
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Does this cleanup all memory?

Post by Demivec »

Just a note on some differences between ClearList() and FreeList().

ClearList() removes all the elements from the list and frees their associated memory, but the list's structure itself still takes up memory. You can immediately add elements to the list again as before (or use any other list functions).

FreeList() performs the same functions as ClearList() and also frees the list's structure and its associated memory. Before adding elements to the list again (or using any other list functions) you would have to use NewList to allocate and initialize the list's structure.
User avatar
Kukulkan
Addict
Addict
Posts: 1415
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Does this cleanup all memory?

Post by Kukulkan »

Hello,

thank you all for the responses. I do not care about if they resist in memory but I don't want to create a memory leak by deletion and filling every now and then. I did a few tests and for me it looks like PB is not only cleaning the main structure but also all "child structures" inside. So, everything seems fine but the documentation does not give any information about cleaning child structures.

Thank you!
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Does this cleanup all memory?

Post by c4s »

Kukulkan wrote:So, everything seems fine but the documentation does not give any information about cleaning child structures.
Agreed, the documentation is a little too shallow on this but for FreeList() it says: "[...] and release all its associated memory." -- So if you know what's meant by that the information is actually there.


Little off-topic: I think the documentation could be clearer about what exactly needs to be done (or is done automatically like in this example) regarding nested structures with complex datatypes: What is automatically initialized? When do we need InitializeStructure()? What is cleared by FreeList(), ClearList() or ClearStructure() and when to use it? Or what is AllocateStructure() for? All of that in a brief coherent step-by-step guide (is this among others what the empty chapters of the included user guide are for?) would be great.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Does this cleanup all memory?

Post by davido »

This may confirm:
http://www.purebasic.fr/english/viewtop ... 08#p371408

However, it would be nice if, as has been suggested, it is stated clearly in the docs.
DE AA EB
Post Reply