Главная страница
    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.45 MB
Время: 0.043 c
15-1183557343
Tonich
2007-07-04 17:55
2007.07.29
VirtualTree


4-1171107679
Vemer
2007-02-10 14:41
2007.07.29
Убрать кнопку с панели задач средствами WinApi.


15-1182910047
Voproshay
2007-06-27 06:07
2007.07.29
Печать почты


2-1183704839
zapis
2007-07-06 10:53
2007.07.29
ADOConnection


2-1183288977
>>DEATH<<
2007-07-01 15:22
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
Английский Французский Немецкий Итальянский Португальский Русский Испанский