rails/rails — pull request #9044 by wangjohn (2013-01-23 16:56:59+00:00)
Title: ObjectSpace for fixing transaction memory bloat

Pertains to issue 776: https://github.com/rails/rails/issues/776.

I created a universally unique identifier (uuid) for all activerecord objects which are associated with transactions. Each transaction contains a set of uuids of AR objects. This means that there are no direct references to the AR objects themselves so they can get garbage collected. On callbacks and rollbacks, I used the ObjectSpace to find all live AR objects and see if their uuid is contained within the transaction.

Note that this fix doesn't work in JRuby because ObjectSpace doesn't exist there. Later I'll be creating a TransactionRecord object which holds a uuid and an AR object, so that ObjectSpace can filter by only transaction records and iterate over a much smaller set to improve performance.

Also added some tests for transaction memory bloat and removed the now unneeded TransactionState object and its associated tests.