jhthorsen/mojo-snmp — pull request #3 by hemmop (2014-03-10 11:00:09+00:00)
Title: Memory cycle in 'walk' and 'bulk_walk'

Hi.

When I'm doing a 'walk' or 'bulk-walk' Devel::Cycle reports memory-cycles. As the memory cycles doesn't show in the unit tests of 'bulk_walk', I've added both methods to the 'live test'.

As seen by the commit "e61737d" (the extended unit test), there are cycles both in 'walk' and 'bulk_walk'.

```
pelle@booty:~/src/mojo-snmp[master]$ TEST_MEMORY=1 LIVE_TEST=1 prove -l t/live.t
t/live.t .. 1/? Unhandled type: GLOB at /usr/share/perl5/Devel/Cycle.pm line 107.

# Failed test at t/live.t line 48.
# Cycle #1
# Mojo::SNMP A->{_pool} => %B
# %B->{127.0.0.1|v2c|public|} => Net::SNMP C
# Net::SNMP C->{_callback} => @D
# @D->[0] => &E
# closure &E, $callback => $F
# $F => &E
# Cycle #2
# Mojo::SNMP A->{_pool} => %B
# %B->{127.0.0.1|v2c|public|} => Net::SNMP C
# Net::SNMP C->{_callback} => @D
# @D->[0] => &E
# closure &E, $end => $G
# $G => &H
# closure &H, $session => $I
# $I => Net::SNMP C

# Failed test at t/live.t line 60.
# Cycle #1
# Mojo::SNMP A->{_pool} => %B
# %B->{127.0.0.1|v2c|public|} => Net::SNMP C
# Net::SNMP C->{_callback} => @J
# @J->[0] => &K
# closure &K, $callback => $L
# $L => &K
# Cycle #2
# Mojo::SNMP A->{_pool} => %B
# %B->{127.0.0.1|v2c|public|} => Net::SNMP C
# Net::SNMP C->{_callback} => @J
# @J->[0] => &K
# closure &K, $end => $M
# $M => &N
# closure &N, $session => $O
# $O => Net::SNMP C
# Looks like you failed 2 tests of 18.
t/live.t .. Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/18 subtests

Test Summary Report
-------------------
t/live.t (Wstat: 512 Tests: 18 Failed: 2)
Failed tests: 13, 18
Non-zero exit status: 2
Files=1, Tests=18, 1 wallclock secs ( 0.03 usr 0.00 sys + 0.31 cusr 0.01 csys = 0.35 CPU)
Result: FAIL
```

When undefining the closures $end and $callback before exiting "$end" (commit "e38bb82"), the memory cycles are gone.

BTW, the ugly
```
Unhandled type: GLOB at /usr/share/perl5/Devel/Cycle.pm line 107.
```
can be removed by using [Capture::Tiny](https://metacpan.org/release/Capture-Tiny) (importing "capture_stderr") and instead of doing
```
test_memory_cycle($foo);
```
use
```
capture_stderr { test_memory_cycle($foo) };
```