Stack overflow but why?

Hi, i'm working on trees and I have successfully make some (working very well...) I mean with value, parents and children and all what I can expect as features for this kind of structure... (weak ref was a key elements by the way.) so far everythink is ok ! ...

But the goal for me is to build my knowledge and there is something which disturb me a lot...
I have tried to build one with simple Box pointer and work... at some point...
until I get a buffer overflow of the main stack EVEN if I ask to only print one key value of a sub node of the tree...
which is perfectly well display on my terminal but next without asking any think else bam !
stack overflow !
I could understand if I ask to print one pointer and the following and so on... I fall in cyclic reference logic and there memory may overflow of course.
but what If I get just one pointer of the tree, and print just his key element value and don't look necessarily at the chained pointer ?
...a Box<Node> is really more than just a pointer on a node ?

-->Finally my question is how to manage a structure with interlink pointer and don't ask to the whole system to fall in cyclic reference whiteout asking to display recursvely ?

At this point I don't want to share heavy code but its sim to be a typical case when a simple node point to his parent and his parent point on that node too
so before falling in madness any light on this aspect of data tree conceptually I mean ?

My apologies for this long text but I really need some explanation from you "the whole community" that should be a very typical case question even perhaps easy...
thanks any way!

If the tree gets fairly deep, my guess is that you have a recursive Drop. That may be only implicit by your Box<Node> pointers, but to solve that you'd have to explicitly impl Drop in a way that avoids recursion. There's an example of this in the too-many-lists book:


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.