Db memory leak fix #5568

PR to test for and fix memory leak from issue #5568

The leak was due to a circular dependency between JoinClause and QueryBuilder, which meant neither object was eligible for garbage collection.

QueryBuilder had a dependency on JoinClause to add "on" bindings, but these can be stored internally on the JoinClause object, and added to the QueryBuilder when compiling the join in the Grammar object.

This removes the dependency and allows expected GC to take place.
Yeah this might not be the best test.

On Friday, September 26, 2014, Mior Muhammad Zaki <notifications@github.com>
wrote:

> In tests/Database/DatabaseQueryBuilderMemoryLeakTest.php:
>
> > +        });
> > +    }
> > +
> > +    protected function runMemoryTest(\Closure $callback)
> > +    {
> > +        $i = 5;
> > +
> > +        $last = null;
> > +
> > +        while($i--)
> > +        {
> > +            $callback();
> > +
> > +            $prev = $last;
> > +            $last = memory_get_usage();
> > +        }
>
> Wonders if this is always going to work on every single request. 1 value
> different could already cause assertion to fail.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/laravel/framework/pull/5825/files#r18121599>.
>