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.

gcnew,

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dogbert1793@yahoo.com - 13 Nov 2007 17:34 GMT
Hello,

Does one need to delete pointers allocated with gcnew?  Or does the
garbage collector do it?

I always though the garbage collector did it, but I saw this example
today on MSDN:

StreamReader^ sr = gcnew StreamReader( "TestFile.txt" );
     try
     {
        String^ line;

        // Read and display lines from the file until the end of
        // the file is reached.
        while ( line = sr->ReadLine() )
        {
           Console::WriteLine( line );
        }
     }
     finally
     {
        if ( sr )
           delete (IDisposable^)sr;   // <-----DELETE HERE ???
     }
David Anton - 13 Nov 2007 23:34 GMT
That looks like a literal conversion of a C# 'using' block.
The 'delete' operator used on a ref type object is equivalent to a call to
the object's Dispose method (which isn't called directly in C++/CLI).  So,
you would normally only need to use the delete operator on a ref type object
when you need to call the object's own cleanup Dispose.  If the object has no
Dispose (the majority of objects), you do not need to use the delete operator.
Signature

http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
C++ to C++/CLI
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB or C# to C++/CLI

> Hello,
>
[quoted text clipped - 21 lines]
>             delete (IDisposable^)sr;   // <-----DELETE HERE ???
>       }

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.