Have followed this thread with interest and now that I find myself using dynamically allocated structures containing strings, I am at last using Freak's tip.
I have one almost daft question, but I want to be absolutely sure that all memory is being freed correctly.
@Freak: in the following code which uses your 'perfect function'

,
Code: Select all
Structure MyStrings
a.s
EndStructure
Procedure test()
Protected *x.MyStrings = AllocateMemory(SizeOf(MyStrings))
*x\a = "Testing!"
*x\a = "Will the preceeding string 'Testing' be freed by this allocation?"
FreePBString(@*x\a)
FreeMemory(*x)
EndProcedure
CallDebugger
For i = 0 To 10000
test()
Next i
CallDebugger
will the command:
Code: Select all
*x\a = "Will the preceeding string 'Testing' be freed by this allocation?"
automatically free the memory allocated by the previous command
?
Common sense dictates an answer of 'yes, don't be an idiot all of your life'

, but as I say I just want to be 100% sure that I am left with no memory leaks.
Thanks.
I may look like a mule, but I'm not a complete ass.