Memory leak with Inline::C

Discussion in 'Perl Misc' started by Anno Siegel, Jul 11, 2004.

  1. Anno Siegel

    Anno Siegel Guest

    I'm seeing a memory leak with the Inline code below. The sub by_inline()
    returns a varying number of scalars, which is probably the crux of the
    matter.

    The code works as expected (returning the exponents of 2 used in the
    binary representation of the argument), but the loop leaks. It leaks
    just the same when by_inline() is called in void context.

    I don't see anything obviously wrong with the code, in particular the
    newly created SVs are carefully mortalized, but I'd like a second opinion.

    I'd also be grateful if one or the other could find the time to run
    the code and report back. For me, the process grows to 500+ MB before
    the loop runs out (I kill it when swapping becomes audible).

    Conditions here:
    Darwin 7.4.0, Perl 5.8.4, Inline 0.44, gcc 3.3

    Anno

    #!/usr/local/bin/perl
    use strict; use warnings; $| = 1;
    use Vi::QuickFix;

    my @res = by_inline( int rand 2 ** 32) for 1 .. 100_000;

    use Inline C => <<EOC;
    void by_inline( int x) {
    int i;
    Inline_Stack_Vars;
    Inline_Stack_Reset;
    i = 0;
    while ( x ) {
    if ( x & 1 ) {
    Inline_Stack_Push( sv_2mortal( newSViv( i)));
    }
    x >>= 1;
    i ++;
    }
    Inline_Stack_Done;
    }
    EOC
    __END__
     
    Anno Siegel, Jul 11, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. s.subbarayan

    Dynamic memory allocation and memory leak...

    s.subbarayan, Mar 18, 2005, in forum: C Programming
    Replies:
    10
    Views:
    758
    Eric Sosman
    Mar 22, 2005
  2. Richard Heathfield

    Leak or no leak ??

    Richard Heathfield, Jul 10, 2006, in forum: C Programming
    Replies:
    4
    Views:
    377
    Richard Heathfield
    Jul 10, 2006
  3. cham
    Replies:
    5
    Views:
    793
  4. Mark Probert
    Replies:
    4
    Views:
    356
    Mark Probert
    Feb 9, 2005
  5. Anno Siegel

    Memory leak with Inline::C

    Anno Siegel, Jul 11, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    125
    Lukas Mai
    Jul 12, 2004
Loading...

Share This Page