.NETGURU
Question about garbage collection
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vc.

Post a new message to this list...

Howard Weiss
I am writing a Managed C++ application.

In my application, I create a modeless sub-form using New. I retain a
pointer to this sub-form in my application.

If the user closes this form, my pointer is still valid. If I interrograte
the instance of the sub-form, the IsDisposed attribute is set.

I want to recreate the sub-form. To do so, I call new again and set my
pointer to the new instance of the sub-form.

What happens to the memory allocated to the old instance of the sub-form? I
am hoping that the framework is keeping reference counts and recognizes when
the old instance is no longer needed and eventually garbage collects the
data.

Can someone verify that this indeed occurs?

Howard Weiss

Reply to this message...
 
    
Jediah L.
Rather than just answering your question, I'm going to give you a couple
links that talk about the Garbage Collection :-)

http://msdn.microsoft.com/msdnmag/issues/1100/gci/
http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/dotnetGCbasics.asp

IsDisposed just means that the object has been disposed however - the object
and its data can still be in memory until actual garbage collection occurs
and the object is compacted out of the managed heap.

Ahh - well - i'll give an answer a shot -

There are so many nuances to the GC process - so I'm not going to give a
straight answer - but - the memory should eventually be collected - but
when/if also depends on how long the form has been around - if it has made
it into gen1 or gen2 - what you have done in your code with your form
reference - what kind of objects you have created on your form - if there
are any finalizers to be called - and other variations.

Part of writing managed applications is that as a whole - you don't really
have to worry about what the CLR is doing with your memory - although - I
highly recommend reading those articles I posted up there - because you can
still really muck your application up but not using your memory wisely.

And I also have to give the disclaimer - that I haven't written managed C++
applications - the C++ stuff I wirte is unmanaged - and the managed stuff I
write is C# - so there is a possiblity that Managed C++ has a different
answer (although by deffinition of 'managed' - it shouldn't).

Anway, I hope the links are useful - and my vague answer made you want to
read the links. :)

"Howard Weiss" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Ioannis Vranos
Howard Weiss wrote:
[Original message clipped]

Yes, it gets garbage collected as far as the form or any of its contents
is not pointed by any other pointer.

However it is not garbage collected immediately but when the CLR decides.

Best regards,

Ioannis Vranos
Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification