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++ / February 2008

Tip: Looking for answers? Try searching our database.

when to call auto_ptr release?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George3 - 19 Feb 2008 09:37 GMT
Hello everyone,

Auto_ptr is convenient because of it saves our work and provides a
framework to auto-management life cycle to reduce potential resource
leak.

But why do we sometimes need to call release method on auto_ptr to go
back to the style of manual management? Remember, when we call release,
we need to delete the object instance manually later.

(here is a sample I modified from MSDN auto_ptr sample code)

Code:
--------------------
 
 // auto_ptr_release.cpp
 // compile with: /EHsc
 #include <memory>
 #include <iostream>
 #include <vector>
 using namespace std;
 
 class Int
 {
 public:
 Int( int i )
 {
 x = i;
 cout << "Constructing " << ( void* )this << " Value: " << x << endl;
 };
 ~Int( ) {
 cout << "Destructing " << ( void* )this << " Value: " << x << endl;
 };
 
 int x;
 
 };
 
 int main( )
 {
 auto_ptr<Int> pi ( new Int( 5 ) );
 Int* pi3 = pi.release ();
 delete pi3;
 }
 
--------------------

thanks in advance,
George
Cholo Lennon - 19 Feb 2008 12:07 GMT
> Hello everyone,
>
[quoted text clipped - 45 lines]
> thanks in advance,
> George

Again with multiposting...  It seems that you can understand the wide range
topic answers that people give you, but you are unable to understand a simple
concept.. multiposting..  The question is: Are you testing our patience?  FYI,
http://www.blakjak.demon.co.uk/mul_crss.htm

--
Cholo Lennon
Bs.As.
ARG

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.