Subject: | Circular references when using add_elem |
Setting the parent attribute of elements adds a circular reference, which leads to memory leaks.
This can be fixed by using Scalar::Util's weaken function and adding
weaken( $elem->{parent} ) if ( ref $elem->{parent} );
after $parent->add_elem($elem);
It's easy to test. You can use Test::Memory::Cycle in the test
memory_cycle_ok($builder, "no memory cycles");
This test will fail if the $elem->{parent} attribute is not weakened.
Fixes can be found in https://github.com/robrwo/SOAP-Data-Builder/commits/fix-memory-leak