aboutsummaryrefslogtreecommitdiff
path: root/freelist.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2016-12-22 17:37:32 -0800
committerJosh Bleecher Snyder <josharian@gmail.com>2016-12-23 09:18:57 -0800
commit10c6e01e1f6eb5087f031a4ae7691b8dc52d34d5 (patch)
tree55c07decf54c82fe1ca6d0c625c91c3f0102cf67 /freelist.go
parentFix freelist.size calculation for large freelists (diff)
downloaddedo-10c6e01e1f6eb5087f031a4ae7691b8dc52d34d5.tar.gz
dedo-10c6e01e1f6eb5087f031a4ae7691b8dc52d34d5.tar.xz
Allow GC to reclaim completed transactions
The existing append-based implementation left a hanging reference to the last tx. For example, if db.txs was: []*Tx{0x1, 0x2, 0x3, 0x4, 0x5} and we removed the second element, db.txs would now be: []*Tx{0x1, 0x3, 0x4, 0x5, 0x5}[:4] The garbage collector cannot reclaim anything anywhere in a slice, even pointers between its len and cap, because the len can always be extended up to the cap. This hanging reference to the Tx could last indefinitely, and since the Tx has a reference to user-provided functions, which could be closures, this bug could prevent arbitrary amounts of user garbage from being collected. Since db.txs is unordered anyway, switch to a simpler--and O(1) instead of O(n)--implementation. Swap the last element into the spot to be deleted, nil out the original last element, and shrink the slice.
Diffstat (limited to 'freelist.go')
0 files changed, 0 insertions, 0 deletions