The docs of an external library I want to use states that for some functions returning char * values the memory of the value returned has to be freed afterwards.
Usually I would define and use the declare as follows:
...
Declare Function GetWhatever Lib "SomeLibrary" () As CString
Dim s As String = GetWhatever()
Return s
End Function
But there is no possibility to free the memory of the returned CString.
So I changed the code to:
...
Declare Function GetWhatever Lib "SomeLibrary" () As Ptr
Declare Sub free Lib "libSystem.dylib" (p As Ptr)
Dim mb As MemoryBlock = GetWhatever()
Dim s As String = mb.CString(0)
free(p)
Return s
End Function
Is that the correct way to free the memory for the return value?
Or does the Xojo framework free the memory of the CString in the first example automatically?