Just a simple question about WIN32 api.
I have a function that connects to MySQL using the MySQL C API, and that retrieves a linked list of pointers to structs.
So in a dialog callback I fill a ListView
control by these elements, and attach every element struct pointer to a row in ListView
.
The question is: should I free the pointers after removing all items from ListView
by LVM_DELETEALLITEMS
for example when I click a refresh button?
Or do the WIN32 API frees them for me?
When deleting items from a list view, you are responsible for cleaning up any resources that are referenced through the lParam member of the LVITEM structure. The Windows API will not do this for you.
In fact, the Windows API cannot do this for you. It has no way of knowing, whether the pointer points to memory allocated using new
, malloc
, IMalloc
, or any other allocator. Or maybe the pointer points into a statically allocated array, and doesn't need to be freed altogether. Or it may not even be a pointer, but rather a hash value for sorting, or an index into some other structure.
Since only you know, how to interpret the lParam, all responsibility with respect to resource management is on you. Contrary to some opinions, C++ will not help you here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With