Skip to content

value() severely leaks memory #54

Description

@a-adam

... probably due to its implementation as "lvalue sub" - precisely the size of
the structure that is passed to it, every time.
happens on run-off-the-mill debians, 11 and 12, but i'm guessing it's a general
problem.

#!/usr/bin/env perl
use strict;
use warnings;
use JSON::Path;
use Memory::Usage;
my $data = {
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa => 1,
    bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb => 1,
    cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc => 1,
    dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd => 1,
    x => 1,
};
my $mu = Memory::Usage->new;
$mu->record('before');
my $got = 0;
for (1..1_000_000) {
    $got += JSON::Path->new('$.x')->value($data);
}
$mu->record('after');
print "got=$got\n";
$mu->dump;

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions