Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2007

Tip: Looking for answers? Try searching our database.

Do managed strings have a deterministic destructor?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Duncan Smith - 08 Nov 2007 15:28 GMT
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
Ben Voigt [C++ MVP] - 08 Nov 2007 15:40 GMT
> 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
[quoted text clipped - 3 lines]
> 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.

> {
> String^ str = gcnew String( messageText );
[quoted text clipped - 7 lines]
>
> Duncan
Mark Salsbery [MVP] - 08 Nov 2007 17:08 GMT
> 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
[quoted text clipped - 5 lines]
>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

Signature

Mark Salsbery
Microsoft MVP - Visual C++

> {
> String^ str = gcnew String( messageText );
[quoted text clipped - 7 lines]
>
> Duncan

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.