And there's plenty of reason to want to learn how to perform cleanup.

Frankly, I can't think of a worse way of doing it than in an END{} block - especially if it's one that actually allocates more memory.

There's no reason to believe it would be the same.

You haven't checked ??
You tell someone to do END { string_reverse( undef ); }, but you don't know if it will work as intended ....
Update: I finally got FFI::Platypus working and was able to verify for myself that, with FFI::Platypus, "undef" does, indeed, get received as "NULL". The END{} block is therefore working as intended.

Finally, you're incorrect assuming that the termination of a Perl interpreter only occurs when the program is unloaded (i.e. when process exits, execs, etc).

I didn't even know that I had made such an assumption. Thank you for that information. (I've learned so much about myself from you, over the years ;-)
I believe that whenever an END{} block is executed, it is immediately followed by a cleanup that would have freed any memory that the END{} block frees.
I don't see any point in using an END{} block to do something that would have happened next anyway.

Of course, it's a different matter if it turns out that there are instances where an END{} block will be executed, but without the following cleanup.
In such a case, I agree that the END{} block approach is better than nothing, but it still defers the freeing of memory to much later than a half-decent programmer would allow.
The best way that I know of is to have the function that assigns the memory, free the memory. But we haven't even touched upon that in this thread.

Cheers,
Rob

In reply to Re^4: FFI::Platypus: Replace malloc with GC_MALLOC? by syphilis
in thread FFI::Platypus: Replace malloc with GC_MALLOC? by karlgoethebier

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.