FoundationDB/sql-layer — pull request #1160 by MMcM (2014-01-08 23:31:23+00:00)
Title: Direct causing memory leak calling stored procedures

This fixes the reported problem in two ways.

First, the actual bug. Non-static thread-locals are tricky. Since the assumption is that threads have a shorter lifetime than TLs, the map is in the thread, using weak references. Which means that any circular reference to the key (the ThreadLocal instance) can prevent it and the thread's value from being GCed. For instance, a path from the per-thread object back to the key or from the key to the non-static field it lives in. Fix ```DirectContextImpl``` to follow these guidelines. I'm actually not clear why ```ConnectionHolder``` is per-thread, since the DC is itself per-thread. It would seem to be addressing uses of multiple threads within the called routine, which I very much doubt works. But I didn't change any of that. I just made the relevant inner classes static to avoid the implicit back-reference.

Second, turn off Direct in routines by default. The idea of a light-weight in-server ORM is very attractive. But it's clear that the design and implementation we have now haven't received enough attention to include it as an advertised capability.