Search:
Namespaces
Discussions
.NET v1.1
Feedback
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...
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com