The compositor leaks memory when the node tree contains unavailable links. That's because the compositor doesn't ignore those links when computing the reference counts for outputs. To fix this, check if the output is logically linked and return 0 in case it isn't.