PC Review


Reply
Thread Tools Rate Thread

destrucor & GC ?

 
 
Sagaert Johan
Guest
Posts: n/a
 
      28th Apr 2007
Hi

If my destructor of my class (derived from usercontrol ) never gets called ,
does this mean that its not collected by the GC and hence
allocated memory is not freed ?

Is there a way to find out whats prevents the GC to collect this object ?

Johan




 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      28th Apr 2007
Sagaert,

It's not a destructor, it is a finalizer.

If it never gets called, that doesn't mean that it is never garbage
collected. If you have passed your object reference to the static
SuppressFinalize method on the GC class, then your class will never have the
finalizer called. This is typical when you have implemented the IDispose
interface properly (because your implementation will pass itself to the
SuppressFinalize method so that the finalizer is not called, because you
should have done all the cleanup necessary in the Dispose method) and the
Dispose method is called by people using your class.

The only thing that would prevent GC from collecting an object is
because something is holding a reference to that object, and something is
holding a reference to that object, or it is rooted, and so on, and so on.

You should not depend on the finalizer to indicate when an object has
been GC'ed if you have implemented the IDisposable interface.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Sagaert Johan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> If my destructor of my class (derived from usercontrol ) never gets called
> ,
> does this mean that its not collected by the GC and hence
> allocated memory is not freed ?
>
> Is there a way to find out whats prevents the GC to collect this object ?
>
> Johan
>
>
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:34 AM.