bumptech/glide — pull request #120 by sjudd (2014-09-05 23:42:25+00:00)
Title: Don't call executePendingTransactions.

Fixes #117

We call ``executePendingTransactions()`` because the sub-fragments we use to store RequestManagers and observe lifecycles per fragment/activity are not added synchronously in the ``commitAllowingStateLoss()`` call. Instead they are posted to the main thread and run in the next loop.

This means that if we have two ``Glide.with(fragment/activity)`` calls in a row before we've added our sub-fragment we could end up adding two sub-fragments instead of one. ``executePendingTransactions()`` forces the fragments to be added synchronously so our second ``Glide.with()`` call will find the sub-fragment and not add a second one.

However it looks like certain classes, like FragmentPagerAdapter, also call ``executePendingTransacations()`` which means it's not safe for us to do so. In turn that means we need some other way to tell whether or not a transaction is pending so we can still avoid adding multiple sub-fragments.

I've done so by keeping a temporary map of fragment manager to pending sub-fragment. Posting a message to a Handler that removes each temporary entry when we call ``commitAllowingStateLoss()`` ensures that the entry is removed when the sub-fragment is added and avoids memory leaks.

If anyone has any comments I'd welcome them, this is not particularly simple.