Does WINAPI automatically free memory attached to controls?

Just a simple question about the WIN32 api.
I have a function that connects to MySQL using the MySQL C API and retrieves a linked list of pointers to structures.

So, in the dialog callback, I populate the ListView element with these elements and attach each struct pointer element to a row in the ListView .

Question: should I release pointers after deleting all the items from the ListView on LVM_DELETEALLITEMS , for example, when I click the refresh button?
Or does the WIN32 API release them for me?

+5
source share
1 answer

When you remove items from the list view, you are responsible for clearing any resources referenced by the lParam element of the LVITEM structure; the Windows API will not do this for you.

In fact, the Windows API cannot do this for you. He does not know if the pointer points to the memory allocated using new , malloc , IMalloc or any other allocator. Or maybe the pointer points to a statically allocated array and does not need to be freed at all. 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 lParam, all responsibility for resource management lies with you. Unlike some opinions , C ++ will not help you here.

+5
source

Source: https://habr.com/ru/post/1261804/


All Articles