My guess is that you are failing to mortalise the SV which you are populating with the inbound data. If you posted the code, it would probably be the work of a few minutes to confirm that or otherwise track the leak down.

The code is too substantial to post, but maybe there is something I have wrong WRT to mortality.

#!/usr/bin/perl use strict; use warnings FATAL => qw(all); use Inline 'C'; my $test = eg(); reportHash($test); reportScalar($test->{x}); $test = undef; __DATA__ __C__ SV *eg () { HV *rv = newHV(); hv_store(rv, "x", 1, newSVpv("hello", 0), 0); return newRV_noinc((SV*)rv); } void reportHash (SV *ref) { HV *hash = (HV*)SvRV(ref); fprintf(stderr,"rc: %d\n", SvREFCNT((SV*)hash)); } void reportScalar (SV *s) { fprintf(stderr,"rc: %d\n", SvREFCNT(s)); }
My understanding is that that since $test has a reference count of 1, and the SV inside it has a reference count of 1, that $test=undef should free the memory used. Running that in a while(1) loop seems to confirm this -- there is no growth. Where in this code do you see an issue? Everything else follows the same pattern (I am not using the inline stack).

In reply to Re^2: Tracing memory leak by halfcountplus
in thread Tracing memory leak by halfcountplus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.