How to to TreeViewItem not to delete subItems

I cant find a way to tell TreeViewItem not to delete SubItems when it closes and  also when the Item scrolls out of view? I am having a lot of issues with dangling pointers cause Items keep deleting themselves.

TreeViewItems are transient objects that can come and go - they're designed that way on purpose! If you have dangling pointer crashes, then you need to fix the object ownership patterns in your code!


Thanks I was using createItemComponent() to use custom components, I found out that only the customComponents get deleted, but the actual TreeViewItem object never gets deleted unless I explicity say so. So I moved my data into my TreeViewItem. It seems to work now.