I want to create a (heap)buffer and store it to a wchar_t. The following code shows how the buffer is created:

void MyClass::CreateString(TDesC16 &aDes)
HBufC16 *buffer = HBufC16::NewL(aDes.Length() + 1);
TPtr16 ptr16 = buffer->Des();
m_MyString = (TText16*)ptr16.PtrZ();

The variable m_MyString is a member variable of type wchar_t *. When I call "delete m_MyString" the User Panic 42 is raised (pointer does not point to a valid cell).

I understand that I can't delete this pointer directly because the HBufC object points to another address. How can I delete this pointer or is there another possibility to create a real wchar_t* with Symbian?