question about reference count on WdfCollection

If for example I create a list in the following way:

stringAttributes.ParentObject = list_1;
status = WdfRegistryQueryMultiString(ServiceRegKey, ValueName, &stringAttributes, list_1);

and then put the item in a second list too, the reference count of every wdfstring in the list is 2.
In the the second list e.g. list_2 the items has now the parents of list_1.
How do I correctly free the items from list_2?
Is it correct if I do nothing or must I call wdfCollectionRemove on each item on list_2 to clean up correctly?
What happens if I call WdfObjectDelete(list_2) internally?
I know that I could give the items in list_1 no parent object but it is nice if the list delete the items automatically.
What happens if I call WdfObjectDelete(list_1) before WdfObjectDelete(list_2)?

Here’s an idea: Why not make your code as easy to read, understand, and maintain as possible? If you have these questions, won’t the next person who maintains your code also have these questions?

So… don’t be “cute” by having the list parent objects that are on the list and try to get them auto-deleted. Just remove the items, delete them, then delete the lists.

Strive for code clarity. Ease of understanding. That is simplicity, which is the essence of good engineering.

Peter

Mak wrote:

If for example I create a list in the following way:

stringAttributes.ParentObject = list_1;
status = WdfRegistryQueryMultiString(ServiceRegKey, ValueName, &stringAttributes, list_1);

and then put the item in a second list too, the reference count of every wdfstring in the list is 2.

In the the second list e.g. list_2 the items has now the parents of list_1.

How do I correctly free the items from list_2?

It’s possible that I have missed something, but when I look through the
source code, I don’t see that a WDFCOLLECTION cares at all about object
parentage.  When an object is added, its reference count is bumped. 
When an object is removed, its reference count is reduced, and if it
goes to 0 it is deleted. When a collection is deleted, all of its
objects get their reference counts reduced.

That’s certainly the most intuitive implementation.

Is it correct if I do nothing or must I call wdfCollectionRemove on each item on list_2 to clean up correctly?

You must remove it from the collection.

What happens if I call WdfObjectDelete(list_2) internally?

Then all those strings will have their reference counts set back to 1.

I know that I could give the items in list_1 no parent object but it is nice if the list delete the items automatically.

What happens if I call WdfObjectDelete(list_1) before WdfObjectDelete(list_2)?

I believe it all works the way you would expect.

Peter: thanks for your suggestion. I think about it.
Tim: thank you too.