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 / .NET Framework / New Users / April 2006

Tip: Looking for answers? Try searching our database.

gcnew but NO gcdelete

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bern11 - 30 Apr 2006 20:02 GMT
    I still have a bit of problem with this one since pointer management is
such a critical task in C/C++ programming.  I've read it, I understand
it, but I gotta ask:  There is no gcdelete function for objects created
with gcnew.  Simple set the handle to nullptr and the system will
destroy it.  Correct?  If it is assigned to another object through a
second gcnew call, the first object will also be detroyed (unless
another reference has been made to it), correct?
Barry Kelly - 30 Apr 2006 20:32 GMT
> Simple set the handle to nullptr and the system will
> destroy it.  Correct?  

At some point in the future, probably during an allocation, a GC will
occur. If the memory being pointed to by the pointer is no longer
referenced anywhere, then it will be reclaimed. Things are more
complicated when there is a finalizer, of course.

> If it is assigned to another object through a
> second gcnew call, the first object will also be detroyed (unless
> another reference has been made to it), correct?

Nothing will be destroyed straight away in a deterministic fashion. If
you need deterministic cleanup then use the new C++/CLI destructor
semantics (i.e. C++/CLI destructors get renamed to Dispose(), and the
class implements IDispose), and allocate the object on the "stack" as a
local (it will really still be a heap-based object, but behind the
scenes Dispose() will be called automatically).

-- Barry
bern11 - 30 Apr 2006 22:59 GMT
Thanks for the reply.  I don't need deterministic cleanup.  It just
feels strange to not delete.  (I almost wish microsoft had a gcdelete
entry with your explaination in their help system - simply because any C
programmer new to Visual Studio will be looking for it).

>>Simple set the handle to nullptr and the system will
>>destroy it.  Correct?  
[quoted text clipped - 16 lines]
>
> -- Barry

Rate this thread:







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.