It didn't use ownership, and I don't think that's the paradigm, but I did something like this in D by tagging allocating members with a user defined attribute which counted in bytes the allocated memory the summed it for the whole tree (structure).
Not worth the effort but it can be done in not much code
Not worth the effort but it can be done in not much code