Xojo.Core.MemoryBlock Returning junk

I have an encryption method that on decryption returns the results as a Xojo.Core.MemoryBlock. In Debug I can see both the returning variable I created and the return value (ie just before it exits the method) and this contains the correct text, but the Xojo.Core.MemoryBlock that collects the returning value contains random junk ie not the same text at all.

Yet, if I return a Base64 of the Xojo.Core.MemoryBlock as Text instead, then decode it outside the method the text is OK.

Is it OK to have Xojo.Core.MemoryBlock as a Return type, or is it unreliable?

Be aware that a Xojo.Core.Memoryblock can refer to external memory. If that memory is released, there may be garbage if memory gets reused later.

So even if you use it immediately, it may be be unreliable. I will have to return as Base64 Text then. Thank you.

What happens if you create the MB outside the method and pass it ByRef? Not saying that’s a solution, but it would tell you if it’s an issue with the MB going out of scope?

Good suggestion.

Or as a global property. Many ways to skin a cat.