Subject: | Memory leak with multiple assignment to string member |
Date: | Sun, 28 Sep 2014 22:29:05 +0200 |
To: | bug-Inline-Struct [...] rt.cpan.org |
From: | Heinz Knutzen <heinz.knutzen [...] gmail.com> |
Define a struct with member of type "char *".
If you assign a new string to this member, memory of the previous value
isn't freed.
Example program:
============================================
use strict;
use warnings;
use Inline C => <<'END', STRUCTS => 1;
struct Foo {
char *str;
};
END
my $count = shift;
my $o = Inline::Struct::Foo->new();
my $str = 's'x100000;
for (1..$count) {
$o->str($str);
}
============================================
Memory usage:
$ /usr/bin/time -f%M perl inline-struct-multi-str.pl 10000
4764
$ /usr/bin/time -f%M perl inline-struct-multi-str.pl 100000
12524
$ /usr/bin/time -f%M perl inline-struct-multi-str.pl 1000000
90144
$ /usr/bin/time -f%M perl inline-struct-multi-str.pl 10000000
866324
Used versions:
- Inline-Struct-0.11
- Perl v5.18.2