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++ / July 2004

Tip: Looking for answers? Try searching our database.

Garbage Collection - Pointer out of scope, or not?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Prenter - 23 Jul 2004 19:16 GMT
Hi, I've got a question about .NET and pointer scope.  Basically I'm trying
to find out how smart .NET is with it's garbage collection and realizing
when a variable is no longer used.

For the sake of this question, regardless of poor programming practices,
lets say I have a custom object which has a public variable called "fs"
which will be a pointer to a FileSteam (FileStream*).  And then lets say
that in one of my functions, I create a different FileStream, call it "fs2",
but point "fs" to "fs2", so that both FileStream pointers are pointing at
the same FileStream object.

I would assume, that at the end of the function, "fs2" should go out of
scope.  Is .NET smart enough to realize that "fs" is still pointing to the
object and not garbage collect it?  Or will it eventually be garbage
collected, leaving "fs" pointing to nothing?

/\/\ark
Ronald Laeremans [MSFT] - 23 Jul 2004 23:11 GMT
The object will not be subject to GC as long as there is at least 1 live
reference to it. That is more or less the essence of any GC system.

Ronald Laeremans
Visual C++ team

> Hi, I've got a question about .NET and pointer scope.  Basically I'm
> trying
[quoted text clipped - 15 lines]
>
> /\/\ark

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.