deletion of System::String

F

fade

Good night

I'm trying to convert a CString into a System::String on a MFC project,
this way:

CString t1("Hello, World!");

#pragma push_macro("new")
#undef new
System::String *s1 = new System::String(t1);
#pragma pop_macro("new")

Everything works ok, but if I try to free s1

delete s1;

an error occurs.
error C3841: illegal delete expression: managed type 'System::String'
does not have a destructor defined

Shouldn't I delete s1? How's responsible for that?
If I'm the responsible, how do I free s1?

Thanks in advance and Merry Xmas to all
 
B

Bruno van Dooren [MVP VC++]

#pragma push_macro("new")
#undef new
System::String *s1 = new System::String(t1);
#pragma pop_macro("new")

Everything works ok, but if I try to free s1

delete s1;

an error occurs.
error C3841: illegal delete expression: managed type 'System::String'
does not have a destructor defined

Hi,

You don't have to free the String. The garbage collector will do that for
you, once it detects that noone is using it anymore. I.e. all managed
pointers to it are out of scope, and it is not pinned.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top