Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2007.07.29;
Скачать: CL | DM;

Вниз

CustomData   Найти похожие ветки 

 
Trible   (2006-12-14 22:16) [0]

Здравствуйте.
Вопрос к в первую очередь к Владимиру.
Написанный компонент содержит дополнительный record (указатель в CustomData).
в книге написано что CustomData освобождается, при уничтожении компонента.
А если там PStrlist, он автоматом освободиться или его отдельно
нужно освобождать?


 
mdw ©   (2006-12-15 13:21) [1]

Нет, ничего не освободит.
Лучше использовать CustomObj, дам деструктор есть.


 
Trible   (2006-12-15 13:48) [2]

Так и думал. Спасибо. Да мне уже неохота переписывать..
Освобожу в Destroy самого компонента.


 
thaddy   (2006-12-16 11:36) [3]

To add a bit of explanation:

CustomData and CustomObj are both useful for extending KOL controls.
CustomData is for Data, like arrays, records, etc. and the data is indeed freed.
CustomData points to a block of actual contiguous memory.

CustomObj is intended for objects and this object is indeed free"d.
CustomObj datasize is a pointer to an object.
Now a pointer to object has a size of 4 bytes, so when you attach this to CustomData, only this pointer - 4 bytes- is free"d and the object itself causes a memory leak.....

If you need to use both CustomData and CustomObj, make shure you call "AddToAutoFree" for the object that is attached to CustomData.
In that case everything works fine.

IMO the best place to do that is to override "init" and create the object for Customdata there and call AddToAutoFree.

Ofcourse this is also a good place to Create the object attached to CustomObj, but the call to AutoFree is not necessary in that case, because it is already done for you.


 
Trible   (2006-12-16 14:20) [4]


> only this pointer - 4 bytes- is free"d and the object itself
> causes a memory leak


hem, didn"t know about that. Are you really sure?
Because I specially downloaded some of the componets wrote by Kladov.
exactly - KOLSoundCtl. And here Kladov use Customdata (TSoundCtlData) but
didn"t free it!

And the second. Can I free Pstrlist (which is in customdata) in destructor of the component?


 
Trible   (2006-12-16 14:21) [5]

http://www.kolnmck.ru/files/components/media/kolsoundctl.7z


 
thaddy   (2006-12-16 18:43) [6]

But it is exactly as I explained:
[CODE]
// in constructing function
 GetMem( D, Sizeof( TSoundCtlData ) ); // allocates memory, not instantates object
 FillChar( D^, Sizeof( D^ ), 0 );
 Result.CustomData := D;
[/CODE]
This is free"d automatically by a call to freemem.

In case of an object it may need finalization, which never happens.

Question two: yes, you can override destroy, because it is virtual.
AddToAutoFree is more convienent, I think.
As is putting most of the constructing code (in this case) in the init procedure. (cleaner, I am shure VK agree"s)



Страницы: 1 вся ветка

Текущий архив: 2007.07.29;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.014 c
2-1183376497
infom
2007-07-02 15:41
2007.07.29
Разные языки в одной таблице...


2-1182536652
corsair
2007-06-22 22:24
2007.07.29
Подключение ввода с клавиатуры


2-1183244422
A2618
2007-07-01 03:00
2007.07.29
Рисование пикселей по формуле


2-1183454141
_Asph
2007-07-03 13:15
2007.07.29
Видимость модулей


15-1183523848
шпыён
2007-07-04 08:37
2007.07.29
Вопрос к тем кто в Америке, Зап. Европе и пр.