> ... return the 1978 for the second debug? If the memory is freed, the value should exist anywhere in memory, right?
By freeing the memory, you just tell the OS that you do not need it anymore. What the OS
then does with it cannot predicted.
The the memory (and its content) can remain for quite a while, or be invalidated
immediately. You may even receive the exact same pointer in a future AllocateMemory() call.
So if you have sensitive Information (like a password), overwriting it with 0 might be a good
thing before freeing the memory.
As for freeing the structured memory: Fred promised a function, but we are still working on
Linux, and with the Mac inbetween the next Update for Windows will be a while.
Using FreeMemory() on the PB strings is something you should do. Yes, i know it seems to work. (at least on some Windows versions)
The truth is though, that PB uses a different Memory heap for AllocateMemory and for the string management.
So theoretically, freeing the one thing with the function for the other (according to the API docs) should not work.
The Memory management of Windows is known to be very forgiving in this respect, so usually it works, yes.
I do not know if this is the case for all Windows versions though. Also the string handling on Linux/Mac is different, so it probably won't work there either.
Here is a very simple trick, that does the job quite nicely. It works on all OS, in PB 3.94 as well as 4.00 and probably will with future Versions as well.
The perfect function so to say
. Its all about tricking PB into freein the String:
Code: Select all
Procedure FreePBString(*Address)
Protected String.String ; the String Structure contains one String element, which is initialized to 0 on procedure start
PokeL(@String, *Address) ; poke our strings address into the structure
EndProcedure ; when returning, PB's string free routine for the local structure will actually free the passed string.
Use it like this:
Code: Select all
Structure MyStrings
a.s
b.s
c.s
EndStructure
Procedure test()
Protected *x.MyStrings = AllocateMemory(SizeOf(MyStrings))
*x\a = Space(4000)
*x\b = Space(4000)
*x\c = Space(4000)
FreePBString(@*x\a)
FreePBString(@*x\b)
FreePBString(@*x\c)
FreeMemory(*x)
EndProcedure
CallDebugger
For i = 0 To 10000
test()
Next i
CallDebugger