I don’t know this code exactly, but I’d guess that the remove/free functions are not called, because the elements are removed and freed all at once.
Typically, when a mempool is used, you just allocate a bunch of objects in a preallocated memory buffer. Then, when you don’t need these objects anymore, you just free the entire buffer instead of all objects individually.
The same is probably true for the treehash thing.
Hope that helps you figuring out what is really going on.
Well, that’s how I assume this issue is being dealt with somewhere in the code, but I’m not actually sure of that yet.
It just, currently, seems like it would be more correct that for every call to MEM_freeN( ""TreeElement"" ) there should immediately precede calls to BKE_outliner_treehash_remove_element() BLI_mempool_free().
This is because tselem = BLI_mempool_alloc(soops->treestore); BKE_outliner_treehash_add_element(soops->treehash, tselem); were both called for every TreeElement allocated.
I, guess, I’ll just take you at your word, and assume nothing further needs to be done when calling MEM_freeN( ""TreeElement"" ) inside outliner_free_tree_element()