Memory/KDTree bugfix (second try)

There is a subtle bug having to do with KDTree not making a copy of the points list, which causes a problem when memory is in effect. This fixes it. It also adds an "assert" farther down that indicates the nature of the problem.

This bug is currently not checked in the tests, but the changes in my next PR revealed it. My next PR is an API change, however, so I thought I'd get this PR in first, which is a no-brainer.