Added support for a free() function for node contents

When weak references are used, the tree implementation must know how to
free a node's contents, because the outside code can not know when the
last weak reference is released.