AVLTree lazarus / 21-General ---------------------------------------------------------------------- Amir61 · 2025-05-04 05:10 Hi there,  What is the role of TAVLTreeNodeMemManager in the avl_tree.pp and how I can disable it (should I disable it)? ---------------------------------------------------------------------- Amir61 · 2025-05-04 05:32 To give more context, I have a code that creates several AVLTrees, and my code fails when I am freeing my AvlTrees (because TAVLTreeNodeMemManager.DisposeNode says "'%s.DisposeNode: FCount (%d) is negative. Should not happen.'"). But when I add, `AVL_Tree.NodeMemManager := nil;` (disabling the NodeManager), the code runs fine. ---------------------------------------------------------------------- cdbc · 2025-05-04 06:03 Hi I would leave it in and learn how to use it. It helps your application's speed and prevents 'Heap-Shredding' (a lot of small allocs & deallocs of mem). Don't free the nodes, but just return them to the nodemanager, it will dispose of them in the end. Regards Benny ---------------------------------------------------------------------- marcov · 2025-05-04 11:27 The nodememorymanager is a cache for nodes, mass allocating and administrating them.  It has been in since nearly forever. Probably your problems stem from a bug in your code (like passing nodes from one avltree to another, crossing nodememorymanager domains). It might be wise to try to fix the bug rather than circumventing it by disabling nodemanager. ---------------------------------------------------------------------- Amir61 · 2025-05-05 04:28 You are right I was able to fix the bug. But still curious about what TAVLTreeNodeMemManager whether I should disable it or not: I use the AVLTree to create an inverted index and then store the sorted key, values on file. I do not have any delete/dispose operation on the nodes (before end of the program). Thank you, ---------------------------------------------------------------------- cdbc · 2025-05-05 05:57 Hi To summarize marco's and my posts: "The nodememorymanager is a cache for nodes, mass allocating and administrating them.  It has been in since nearly forever." + "It helps your application's speed and prevents 'Heap-Shredding' (a lot of small allocs & deallocs of mem)." Just leave it ENABLED and let it do its job! Regards Benny ---------------------------------------------------------------------- scribly · 2025-09-25 00:30 Small bump, but just wanted to point out that the default TAVLTreeNodeMemManager is not thread safe (at least not in 4.2).  So if you where to clear out a tree in another thread you'll get some weird errors when at the same time some GUI controls resize(e.g update a label showing progress of deletion), as they also make use of AVLTree.  This also affects TMap controls and similar as those also rely on TAVLTree. So make sure you assign a custom NodeMemManager each time you make a new tree in another thread (Can be iffy with TMap )