> hi, 
> 
> if u do:
> 
>   ptrMystring = MemPtrNew(10);
>   StrCopy( ptrMystring, "label")
>   CtlSetLabel( ptrMyControl, ptrMystring );
> 
> do we need 
>   - to free the original chunk held in the control?
>>>

No.  From what I understand, when the control is instantiated, one chunk of
memory is allocated for the control's data and its string.  The internal
label pointer basically points back inward to memory allocated at the same
time.  This single chunk of memory is freed when the control is freed.
Thus, you get a drawing like this:


ptrMyControl --> +-------+-------+--------+--------+--------+
                 | data / values | labelP | 'origstring'    |
                 +-------+-------+---+----+--------+--------+
                                     |     ^
                                     +-----+

This is one chunk of memory.  When the control is freed (by leaving the
form), that one chunk of memory is freed.  However, if you do a
CtlSetLabel, you get:


ptrMyControl --> +-------+-------+--------+--------+--------+
                 | data / values | labelP | 'origstring'    |
                 +-------+-------+---+----+--------+--------+
                                     |
                                     |
                                     +--->+--------+--------+
                                          | 'mynewstring'   |
                                          +--------+--------+

Now, when the form disappears and frees the original chunk of memory, the
new chunk of memory will be orphaned.

<<<
>   - to free the chunk we've allocated via MemPtrNew?
>     - if yes when to do so?
>>>

As per the picture / explanation above, you should do it when the form
closes.

Actually, I think it goes even further than this.  I think all of the
memory for the whole form is allocated in one chunk and all the elements in
the form are similarly in one contiguous block of memory that is just freed
once when the form exits.  That's harder to draw though.


If this is wrong, someone please correct me.  This is just the
understanding that I've picked up over time.

Reply via email to