Open pulsar-heart opened 1 year ago
Update: this is still an actual issue because in the case that both the left and right childs are None, I don't know a workaround for "node = None"-- just changing the value to None causes issues down the road.
Consider line 5, where you say:
5 node = None
This does not delete the object that node
references. Instead, it just makes node
point to None
. The previous parent of node
still will be pointing to the object, and so you must delete the node inside the parent by setting it's left/right child to None
.
That's an extremely brief explanation, but pictures and in-person conversation would be needed for a more detailed explanation.
I'm encountering a memory management issue in my _remove function, and although I figured out how to resolve it, I don't understand why things work the way they do. Here is some code for the function:
When I use the notation on lines 5 and 7, of the form "node =" this does not actually alter the input node. However, I am able to fix this issue with the strategy I adopt in lines 9 and 10--altering the value and right child of the node actually does alter the input node itself. I am confused as to why this might be the case. Does anyone have any ideas?