Why can't we use Multiple inheritance and garbage collector parallelly in .net

Editorial / Best Answer

Pendurti  

  • Member Since Sep-2008 | Sep 11th, 2008


Well C# doesn't support multiple inheritance through classes.

If you want to have multiple inheritance in your program, you need to make use of interfaces. A class cannot inherit from more than one class but a class can inherit from more than one interfaces. So C# supports multiple inheritance through interfaces. 
And multiple inheritance and garbage collection can work independent of each other because, in .NET framework, garbage collection is taken care of by CLR. We can also manually invoke garbage collector using gc.collect(). 

Showing Answers 1 - 11 of 11 Answers

Multiple Inheritance was not allowed in .Net to avoid "Diamond Problem" (Where a class inherits from two classes which are both inherited from a same base class. Then on invoking the base functions the compiler may get confused to call which function). But wht the garbage collector has to do with this is a matter that we need to really look into. I will try to find the answer for this and come back.

  Was this answer useful?  Yes

samantbjain

  • Jan 30th, 2006
 

we can use it . Multiple inheritance is used by interfaces while you can not force GC indipendent of Multiple inheritance . GC run on its own ie when system run out of memory.

  Was this answer useful?  Yes

ameen

  • Feb 10th, 2006
 

grabage collector

there are two types of Garbage Collector

managed garbage collector

see we will declaring variable ,object .. etc in our programes..once this kind of

variable,object goes out of the scope ,they are put into the heap and they r checked r the further existence . once its beeing no longer used garbage collector wil deallcate  mem for the that variable and objects.

Umanaged garbage collector

this was done  mannually and  u will be happen to open a connection with database,will be open the file .etc. while this kind of the thing goes out of the scope

we have to explicitly call the garage colector by calling  the closecommand of the datbase ...once te connection is closed it puts this memmory ino the heep .. and process follws the same

  Was this answer useful?  Yes

FYI, .net doesn't support the multiple inheritance, perhaps you may talk about multi-level inheritance.

In the later case, if a class is inherited from another class, at the time of creating instance, it will obviously give a call to its base class constructor (ie bottom - top approach).? Like wise the constructor execution is takes place in top down approach (ie. base class constructor is executed and the derived class constructor is executed).

So for GC, it will collect only when an object does not have any reference.? As we see previously, the derived is constructed based on base class.? There is a reference is set to be.? Obviously GC cannot be collected.

NITIN

  • Jun 20th, 2006
 

.net doesn't support the multiple inheritance, perhaps you may talk about multi-level inheritance.

In the later case, if a class is inherited from another class, at the time of creating instance, it will obviously give a call to its base class constructor (ie bottom - top approach).?

  Was this answer useful?  Yes

Mob: +91 9849255958

  • Jan 4th, 2007
 

Actually, GC is a low-level thread.  When it gets activated, all other threads in the applications are put on hold.

  Was this answer useful?  Yes

Pendurti

  • Sep 11th, 2008
 

Well C# doesn't support multiple inheritance through classes.

If you want to have multiple inheritance in your program, you need to make use of interfaces. A class cannot inherit from more than one class but a class can inherit from more than one interfaces. So C# supports multiple inheritance through interfaces. 
And multiple inheritance and garbage collection can work independent of each other because, in .NET framework, garbage collection is taken care of by CLR. We can also manually invoke garbage collector using gc.collect(). 

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions