Re: How to allocate new class instance on the heap?
- From: erewhon@xxxxxxxxxx (J French)
- Date: Thu, 26 May 2005 00:48:01 +0000 (UTC)
On 25 May 2005 17:14:26 -0700, chrisspencer02@xxxxxxxxx wrote:
>Just to make sure I understand you:
>
>ClassInstanceVariable := tClassName.Create { ( <constructor
>parameters>) };
>
>This will allocate ClassInstanceVariable on the heap, and will not
>automatically deallocate it when the function declaring
>ClassInstanceVariable exits? Thanks.
Nearly right.
It will put a 4 byte pointer into ClassInstanceVariable
- those 4 bytes point to a chunk of data on the heap
- the chunk of data will not be deallocated when you leave the
function/procedure
- the chunk of data will only be deallocated when you (or if it has an
owner, its owner) does ClassInstanceVariable.Free
What happens to ClassInstanceVariable (just the 4 byte pointer)
depends on where you declared it.
If you are not careful you could land up with an 'orphan' on the heap.
BTW - I would not go around using New and Dispose to create and
destroy Records
- not unless you are doing something really fancy
- just declare them as a Var on the stack and let Delphi create and
destroy them for you
You do (generally) need to zap their contents before using them, as
annoyingly Delphi does not do that for you (except when it does - but
it is better to play it safe)
.
- References:
- How to allocate new class instance on the heap?
- From: chrisspencer02
- Re: How to allocate new class instance on the heap?
- From: Bruce Roberts
- Re: How to allocate new class instance on the heap?
- From: chrisspencer02
- How to allocate new class instance on the heap?
- Prev by Date: Re: How to allocate new class instance on the heap?
- Next by Date: Re: How to allocate new class instance on the heap?
- Previous by thread: Re: How to allocate new class instance on the heap?
- Next by thread: Re: How to allocate new class instance on the heap?
- Index(es):
Relevant Pages
|
|