473,563 Members | 2,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Do managed strings have a deterministic destructor?

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::StreamReade r^ rdr = gcnew IO::StreamReade r("d:\\done.txt ");
delete rdr;
}

Many thanks,

Duncan

Nov 8 '07 #1
2 1041

"Duncan Smith" <DS********@goo glemail.comwrot e in message
news:11******** **************@ t8g2000prg.goog legroups.com...
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/lib...97(VS.80).aspx but it doesn't
come right out and say that the delete keyword calls IDisposable::Di spose
when invoked on an imported managed type.
>
{
String^ str = gcnew String( messageText );
delete str;

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

Many thanks,

Duncan

Nov 8 '07 #2
"Duncan Smith" <DS********@goo glemail.comwrot e in message
news:11******** **************@ t8g2000prg.goog legroups.com...
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

--
Mark Salsbery
Microsoft MVP - Visual C++
>
{
String^ str = gcnew String( messageText );
delete str;

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

Many thanks,

Duncan
Nov 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1266
by: Slawomir Lisznianski | last post by:
Do ref classes indeed support instantiation on the stack? Similarly, can native classes be instantiated on gc heap? When you try to have a ref class instance on the stack, you'll get: R : cannot use this type here without a top-level '^'. When you try to instantiate a native class using gcnew using Visual Studio 2005 Beta 1, you'll get:
11
1945
by: Lloyd Dupont | last post by:
(not I use 2.0, so new return a "normal" pointer and gcnew return a managed one, my question below regarding new concern plain standart C++ allocator) - if I use the default new operator, are all the instance variable initialize to NULL / 0 ? - if there is not enough memory what happend with new ? does it return NULL or throw an exception?...
9
1325
by: Peter Oliphant | last post by:
I would assume in the following that 'instance' being set to 'nullptr' should cause the instance of myClass that was created to no longer have any pointers pointing to it, and therefore be 'destroyed': ref myClass { public: myClass() {} ~myClass() {} // never called !myClass() {} // never called
4
2069
by: Maxwell | last post by:
Hello, Newbie question here for disposing of unmanaged resources in MC++.NET. I have a managed VS.NET 2003 MC++ wrapper class that wraps a unmanaged C++ dll. What I am trying to figure out is what is the "best practice" for disposing of pointers to unmanaged classes that you have newed in your constructor in MC++ For a better description...
5
7049
by: Michael D. Reed | last post by:
I have legacy DLL code written in C++ that is essentially C code, an implementation of a set of formulas used in our industry. There are no DB or GUI interfaces, just exposed methods. I would like to convert it to C# and if that is not possible to manage C++. I want to use the DLL in a larger VB.Net program. Is there a tool that will...
9
2993
by: plahey | last post by:
I have been dabbling in Python for a while now. One of the things that really appeals to me is that I can seem to be able to use C++-style RAII idioms to deal with resource management issues. For those that have no idea what I am talking about (I learn a lot reading posts on subjects in which I am clueless), consider the following code...
3
1157
by: Greg | last post by:
In the following example, where is "n" allocated (e.g. managed heap?) ? public ref class N { .... .... } main() {
16
8771
by: pkoniusz | last post by:
Hello everybody, Been just thinking how actually one could convert the following unmanaged code to the managed C++: struct JustAnExample { char value1; int value2; // etc ....
25
2990
by: Koliber (js) | last post by:
sorry for my not perfect english i am really f&*ckin angry in this common pattern about dispose: ////////////////////////////////////////////////////////// Public class MyClass:IDisposable
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.