Memory leak

José Joaquín Atria
2020-10-20T22:12:52Z

Even when making repeated `GET` requests, the amount of memory used by the process increases at a steady pace. Currently, the following script:
``` raku
#!/usr/bin/env raku

use HTTP::Tiny;

sub fetch {
my $ua = HTTP::Tiny.new: :thro...

Even when making repeated GET requests, the amount of memory used by the process increases at a steady pace. Currently, the following script:

#!/usr/bin/env raku

use HTTP::Tiny;

sub fetch {
    my $ua = HTTP::Tiny.new: :throw-exceptions;
    my $res = $ua.get: 'http://raku.org';
    print $res< status reason >.join: ' ';
}

use Telemetry;

say '        ' ~ T<max-rss>.fmt('%.2f') ÷ 1024
    ~ 'MiB maxrss – before doing anything!!';

loop {
    fetch();
    say ': ' ~ T<max-rss>.fmt('%.2f') ÷ 1024 ~ 'MiB maxrss';
}

generates the below output:

$ time raku -I. t/memory-leak-tiny.raku
        106.921875MiB maxrss – before doing anything!!
200 OK: 152.335938MiB maxrss
200 OK: 153.109375MiB maxrss
200 OK: 153.109375MiB maxrss
200 OK: 153.109375MiB maxrss
200 OK: 153.625MiB maxrss
200 OK: 153.625MiB maxrss
200 OK: 154.140625MiB maxrss
200 OK: 154.140625MiB maxrss
200 OK: 154.140625MiB maxrss
200 OK: 154.398438MiB maxrss
200 OK: 154.398438MiB maxrss
200 OK: 154.398438MiB maxrss
200 OK: 154.65625MiB maxrss
200 OK: 154.65625MiB maxrss
200 OK: 154.914063MiB maxrss
200 OK: 154.914063MiB maxrss
200 OK: 154.914063MiB maxrss
200 OK: 155.171875MiB maxrss
200 OK: 155.171875MiB maxrss
200 OK: 155.429688MiB maxrss
200 OK: 155.429688MiB maxrss
200 OK: 155.6875MiB maxrss
200 OK: 155.945313MiB maxrss
200 OK: 156.203125MiB maxrss
200 OK: 156.203125MiB maxrss
200 OK: 156.460938MiB maxrss
200 OK: 156.71875MiB maxrss
200 OK: 157.234375MiB maxrss
200 OK: 157.234375MiB maxrss
200 OK: 157.492188MiB maxrss
200 OK: 157.492188MiB maxrss
200 OK: 157.75MiB maxrss
200 OK: 158.007813MiB maxrss
200 OK: 158.265625MiB maxrss
200 OK: 158.78125MiB maxrss
200 OK: 158.78125MiB maxrss
200 OK: 159.296875MiB maxrss
200 OK: 159.296875MiB maxrss
200 OK: 159.296875MiB maxrss
...

For reference, the equivalent script using HTTP::UserAgent similarly increases in memory for the first ~20 requests and then remains fixed at ~194.5 MiB.