Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "KOL";
Текущий архив: 2007.07.29;
Скачать: [xml.tar.bz2];

Вниз

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 вся ветка

Форум: "KOL";
Текущий архив: 2007.07.29;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.028 c
15-1183525244
Kerk
2007-07-04 09:00
2007.07.29
Никому нельзя верить?


15-1182701335
koha
2007-06-24 20:08
2007.07.29
Ищу хорошую инфу по компоненту TChart


2-1183533375
Стас
2007-07-04 11:16
2007.07.29
Многооконная программаю. Модал - немодал


15-1182486389
delphino
2007-06-22 08:26
2007.07.29
Создание инсталлятора


2-1183529439
_Asph
2007-07-04 10:10
2007.07.29
Обновление данных в таблице





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский