No, assuming the constructors of neither the derived or base classes were
NOT called, meaning that no objects created in the constructors would be
created, then an instance of TDerived would occupy 16 bytes (12 from TBase
plus 4 from TDerives FAge). Assuming that TDerived's constructor called
TBase's constructor through "Inherited", then TDerived would occupy 552
bytes (12 from TBase + 536 from the TButton created by TBase + 4 from
TDerived's FAge). Remember that TDerived's fields are just an extension of
TBase to TDerived only adds an additional 4 bytes, not another 12.

Again, TDerived's footprint is just a 4 byte extension of TBase's 12 bytes.
So when the TDerived instance is freed, 16 bytes of memory are reclaimed. If
TDerived's destructor does not call the TBase's destructor, then the 536
TButton instance will not be freed causing a 536 byte leak.

Two books that really helped me when I started were:

"Secrets of Delphi 2" by Ray Lischner ISBN 1-57169-026-3
It was published by Waite Group Press

And

"Delphi Component Design" by Danny Thorpe ISBN 0-201-46136-6
Published by Addison Wesley

Both books have been out of print for a long time, but I just checked on
www.half.com and both books are being sold by previous owners. 







-----Original Message-----
From: Alan Colburn [mailto:[EMAIL PROTECTED] 
Sent: Saturday, April 15, 2006 2:10 PM
To: [email protected]
Cc: [EMAIL PROTECTED]
Subject: RE: Re[2]: Class constructor and destructor

Scott --

What a great explanation ... thanks for posting it! As a newbie, I learned a

lot. Can I ask a couple quick follow-ups?

First, from your explanation it seems like when one creates a derived class 
instance (TDerived), including the inherited constructor, then memory is 
allocated for the base class. In your example, a TDerived object would 
occupy 16 bites and TBase would occupy 548 bites, so an instance of TDerived

would require 564 bites. Is that right?

Likewise, it seems like freeing TDerived, without calling an inherited 
destructor, would leave the instance of TBase still in memory, leaking 548 
bites. Is that right?

Finally, I really liked your explanation--it worked well for my learning 
style. Do you have any particular books or internet resources that worked 
well for *you* for learning about OOP and/or Delphi? I figure that something

you found clear might be clear to me, too.

Thanks again -- Al C.


>From: "Scott Kellish" <[EMAIL PROTECTED]>

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to