79720226

Date: 2025-07-30 15:57:05
Score: 1
Natty:
Report link

I ended up declaring a function that deallocates memory that was allocated and returned to cpp code earlier.

And my code looks like this:

public static IntPtr GetText()
{
  return Marshal.StringToCoTaskMemUni(SomeClass.SomeMethodThatReturnsAString());
}

public static void FreeMemory(IntPtr ptr)
{
    Marshal.FreeCoTaskMem(ptr);
}
void OnWriteValue()
{
  char16_t const *string = CSharp::GetText();

  if (string)
  {
    Print(string);
    CSharp::FreeMemory(string);
  }
}

Thanks for your answers.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Sayan