Главная страница
    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
6-1166033544
XfroSt
2006-12-13 21:12
2007.07.29
IndyUDPServer - Адрес назначения пакета, Как узнать в событии UDP


4-1171614711
niko_
2007-02-16 11:31
2007.07.29
Блокировка Ctr+Alt+Del


15-1183467755
Сергей М.
2007-07-03 17:02
2007.07.29
"Непонятка" в FastReport 3.x


15-1183625889
@!!ex
2007-07-05 12:58
2007.07.29
Установка Linux виснет на форматировании винчестеров....


15-1183453560
Bolek
2007-07-03 13:06
2007.07.29
документация по ParadoxSQL





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский