Do managed strings have a deterministic destructor?

  • Thread starter Thread starter Duncan Smith
  • Start date Start date
D

Duncan Smith

If I set a breakpoint on all four lines within the curly brackets in
VS2005, the 'delete str' breakpoint is always removed and the line
itself is removed from the code.

Why is not possible to call delete on a String^ ref type like it is
for other ref handles? Would it be because the String type has no
protected member called Dispose?

{
String^ str = gcnew String( messageText );
delete str;

IO::StreamReader^ rdr = gcnew IO::StreamReader("d:\\done.txt");
delete rdr;
}

Many thanks,

Duncan
 
Duncan Smith said:
If I set a breakpoint on all four lines within the curly brackets in
VS2005, the 'delete str' breakpoint is always removed and the line
itself is removed from the code.

Why is not possible to call delete on a String^ ref type like it is
for other ref handles? Would it be because the String type has no
protected member called Dispose?

That is my understanding. There's some information at
http://msdn2.microsoft.com/en-us/library/ms177197(VS.80).aspx but it doesn't
come right out and say that the delete keyword calls IDisposable::Dispose
when invoked on an imported managed type.
 
Duncan Smith said:
If I set a breakpoint on all four lines within the curly brackets in
VS2005, the 'delete str' breakpoint is always removed and the line
itself is removed from the code.

Why is not possible to call delete on a String^ ref type like it is
for other ref handles?


Would it be because the String type has no
protected member called Dispose?


Yes System::String is not a disposable class (no IDisposable interface).

The StreamReader class, however, IS disposable :)

Mark
 
Back
Top