If you create a Xojo.Core.MemoryBlock using Constructor( ptr ) or Constructor( ptr, size ), it cannot be returned properly by a function even though it seems fine in the method that created it.
For example, this does not work properly:
dim mb as new Xojo.Core.MemoryBlock( p, size )
return mb
This will:
dim mb as new Xojo.Core.MemoryBlock( p )
mb = mb.Left( size )
return mb
You will only see the issue when you examine the returned MemoryBlock in the calling method.
Norman, in the example app attached to the Feedback case, I obtained the Ptr from a classic MemoryBlock. As Eli noted, that classic MB goes out of scope at the end of the function that returns the new MB.
Not a bug - in fact the new mb CANT take ownership of the Ptr - this is by design
What if it came from a DLL etc ?
We cannot take ownership of whatever memory this ptr points at because something else may own it
You’d need to copy the data to be safe
There may be a case for having a way to create from a Ptr AND copy - but thats not how it works today
So quite literally the memory block goes out of scope & gets deallocated & you have a dangling ptr in Xojo code