Skip to content

4.5.1 - Refactor encoder property to weak reference in KeyedContainerImpl and UnkeyedContainerImpl to prevent retain cycles

Latest

Choose a tag to compare

@penny-for-vapor penny-for-vapor released this 31 Jul 09:28
b70a610

What's Changed

Refactor encoder property to weak reference in KeyedContainerImpl and UnkeyedContainerImpl to prevent retain cycles by @makoni in #239

I’ve noticed memory usage growth in my project that is described in vapor/leaf#238

After adding some tests and running leaks, I found that currently there are retain cycles. That PR fixes them.

  4 (352 bytes) ROOT CYCLE: <EncoderImpl 0x1572270d0> [80]
     3 (272 bytes) storage --> ROOT CYCLE: <Leaf.LeafEncoder.(KeyedContainerImpl in _30C79F4310B915184892E56903FC555A)<CodingKeys in Foo #1 in closure #1 (Vapor.Application) async throws -> () in LeafTests.LeafMemoryGrowthTests.testRepeatedRenderMemoryGrowth() async throws -> ()> 0x157227120> [48]
        __strong encoder --> CYCLE BACK TO <EncoderImpl 0x1572270d0> [80]
        2 (224 bytes) __strong data._variant --> <Swift._DictionaryStorage<Swift.String, Leaf.(LeafEncodingResolvable in _30C79F4310B915184892E56903FC555A)> 0x157227170> [192]  item count: 1
           1 (32 bytes) <Closure context 0x157227150> [32]

  2 (128 bytes) ROOT CYCLE: <EncoderImpl 0x156710ad0> [80]
     1 (48 bytes) storage --> ROOT …

This patch was released by @gwynne

Full Changelog: 4.5.0...4.5.1