I experimented with with lib.i. This is untested, but it's what I have so far:
/* lib.i */ % module libspace %{ #include "lib.h" extern x_space * new_space(); extern void destroy_space( x_space * space ); #ifdef PERL_OBJECT #define MAGIC_CLASS _wrap_libspace_var:: class _wrap_libspace_var : public CPerlObj { public: #else #define MAGIC_CLASS #endif SWIGCLASS_STATIC int swig_magic_readonly( pTHX_ SV * SWIGUNUSEDPARM(sv), MAGIC * SWIGUNUSEDPARM(mg) ) { MAGIC_PPERL croak("Value is read-only."); return 0; } #ifdef PERL_OBJECT }; #endif #ifdef __cplusplus extern "C" { #endif XS(_wrap_new_space) { { x_space * result = 0; int argvi = 0; dXSARGS; if ( ( items < 0 ) || ( items > 0 ) ) { SWIG_croak("Usage: new_space();"); } result = ( x_space * ) new_space(); ST(argvi) = SWIG_NewPointerObj( SWIG_as_voidptr(result), SWIGTYPE_p_x_space, 0 | 0 ); argvi++; XSRETURN(argvi); fail: SWIG_croak_null(); } } XS(_wrap_destroy_space) { { x_space * arg1 = ( x_space * ) 0; void * argp1 = 0; int res1 = 0; int argvi = 0; dXSARGS; if ( ( items < 1 ) || ( items > 1 ) ) { SWIG_croak("Usage: destroy_space(space);"); } res1 = SWIG_ConvertPtr( ST(0), &argp1, SWIGTYPE_p_x_sp +ace, 0 | 0 ); if ( !SWIG_IsOK(res1) ) { SWIG_exception_fail( SWIG_ArgError(res1), "in method '" "destroy_space" "', argument " " +1" " of type '" "x_space *""'" ); } arg1 = ( x_space * ) (argp1); destroy_space(arg1); XSRETURN(argvi); fail: SWIG_croak_null(); } } %}
Does that help?

In reply to Re: Perl with Swig C module not releasing memory by Khen1950fx
in thread [Solved] Perl with Swig C module not releasing memory by megaframe

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.